def search(request): if 'query' in request.GET: query = request.GET['query'] if query in util.list_entries(): return util.forwarding(request, query) else: return render( request, "encyclopedia/search.html", { "entries": [ entry for entry in util.list_entries() if entry.lower().count(query.lower()) ], "query": query })
def search(request): if request.method == "POST": data = request.POST.copy(); search_term = data["search_term"] search_data= [word for word in list_entries() if search_term in word] context = { "search_term": search_term, "search_data": search_data } return render(request, "search/search.html", context)
def create(request): if request.method == "GET": return render(request, "create/create.html") else: data = request.POST.copy() title = data["title"] if title in list_entries(): messages.error(request, "Could Not Create Page, Page Exists!") return render(request, "error/error.html") content = data["markdown"] save_entry(title, content) return redirect("wiki_title", title)
def create(request): if request.method == 'POST': title = request.POST['title'] if 'edit' not in request.META[ 'HTTP_REFERER'] and title in util.list_entries(): return render(request, 'encyclopedia/error.html', { 'title': title, }) util.save_form_to_entry(request) return HttpResponseRedirect(title) return render(request, "encyclopedia/create.html", { "form": util.CreateEntryForm(), })
def search(keyword): result = [] i = 0 l = util.list_entries() for x in l: if keyword.lower() == l[i].lower(): return ("test_ok", l[i]) elif keyword.lower() in l[i].lower(): result.append(l[i]) i += 1 else: i += 1 a = result return a
def index(request): #list of entries entries = util.list_entries() if request.method == "POST": #grabing input value that user submitted result = request.POST['search'] search = [] if result in entries: return redirect(f"http://127.0.0.1:8000/{result}") else: for entry in entries: if result in entry: search.append(result) return render(request, "encyclopedia/search.html", {"searches": search})
def create(request): if request.method == 'POST': title = request.POST['title'] text = request.POST['wiki-text'] caseFoldEntries = [entry.casefold() for entry in util.list_entries()] if title.casefold() not in caseFoldEntries and title is not '': util.save_entry(title, text) return HttpResponseRedirect(f'/{title}') elif title is '': return render(request, 'create/create.html') else: messages.add_message( request, messages.ERROR, f'A wiki entry with the title {title} already exists.') return render(request, 'create/create.html', {'text': text}) return render(request, 'create/create.html')
def index(request): # get value from search box if request.method == 'POST': value = request.POST['q'] # check to see if the word typed is a valid page. If so, go there. if util.get_entry(value) is not None: return HttpResponseRedirect(f'/{value}') # if not in list, check to see if typed search is a substring of any titles and display a results list. entries = util.list_entries() filteredEntries = [ entry for entry in entries if value.casefold() in entry.casefold() ] if filteredEntries == []: notFoundResponse = 'There are no entries that match that search.' return render(request, 'search/index.html', {'notFoundResponse': notFoundResponse}) return render(request, 'search/index.html', {'filteredEntries': filteredEntries})
from django.urls import path from . import views from encyclopedia import util topics = util.list_entries() urlpatterns = [ path("", views.wiki, name="wiki"), path("<str:name>/", views.topic, name="topic") ] # for topic in topics: # urlpatterns.append(path(<str:name>topic+'/',views.topic, name = topic))
def index(request): return render(request, "encyclopedia/index.html", { "entries": util.list_entries(), })
def random_page(request): title = random.choice(util.list_entries()) return get_entry(request, title)
def get_entry(request, title: str): content = None if title not in util.list_entries(): content = f'ERROR! Requested page {title} not found' return util.forwarding(request, title, content)
def clean(self): cleaned_data = super().clean() title = cleaned_data.get('title') if title in list_entries(): self.add_error('title', 'Entry with such title already exist!') return cleaned_data
def randomwiki(request): wikiList = util.list_entries() randomArticle = choice(wikiList) return HttpResponseRedirect(f'/{randomArticle}')
def randomChoice(request): entries = util.list_entries() return redirect("display:index", random.choice(entries)) return HttpResponse("Random page here")