def title(request, title): if (get_entry(title) == None): messages.error(request, "Page Could Not Be Found") return redirect("error") else: return render(request, "info/info.html", { "title": title.capitalize(), "info": Markdown().convert(get_entry(title)) })
def edit(request): topic_name = request.GET.get('topic_name') body = util.get_entry(topic_name) return render(request, 'edit/edit.html', { 'topic_title': topic_name, 'body': body })
def random(request): arr = util.list_entries() arr = secrets.choice(arr) return render(request, "info/info.html", { "title": arr.capitalize(), "info": Markdown().convert(get_entry(arr)) })
def random_func(request): random_num = random.randint(0, len(topics) - 1) html_page = markdown2.markdown(util.get_entry(topics[random_num])) return render(request, "encyclopedia/topic.html", { 'topic_name': topics[random_num], 'body': html_page })
def edit(request, title): content = util.get_entry(title) data = { 'title': title, 'content': content, } return render(request, "encyclopedia/create.html", { "form": util.CreateEntryForm(data), })
def index(request): if (request.method == "POST"): data = request.POST.copy() title = data.get('title') contents = data.get('contents') if (util.get_entry(title) != None): raise Exception('An entry already exists with this title!') util.save_entry(title, contents) return redirect("display:index", title) return render(request, 'pages/index.html')
def index(request, entry): response = get_entry(entry) print(entry) print('you are here!') if (response == None): return render(request, "display/error.html") else: response = markdown(response) return render(request, "display/index.html", { "title": entry, "response": response })
def topic(request, name): dict_topic = {} for top in topics: html_page = markdown2.markdown(util.get_entry(top)) dict_topic[top] = str(html_page) if name in topics: return render(request,"encyclopedia/topic.html",{ 'topic_name': name, 'body':dict_topic[name] }) return HttpResponse('<h1 style="font-size:40px">Page not found</h1><br>Sorry, requested page was not found.')
def editPage(request, title): contents = util.get_entry(title) if (request.method == "POST"): data = request.POST.copy() contents = data.get('contents') util.save_entry(title, contents) return redirect("display:index", title) else: return render(request, 'pages/edit.html', { "title": title, "contents": contents })
def edit(request, title): if request.method == "GET": title.replace("%20", " ") return render(request, "create/create.html", { "title": title, "markdown": get_entry(title) }) else: data = request.POST.copy() title = data["title"] content = data["markdown"] save_entry(title, content) return redirect("wiki_title", title)
def save(request): if request.method == "POST": title = request.POST.get('title') body = request.POST.get('textarea') if title.upper() in topics_upper: return render(request, 'create/exist.html', {'topic': dict_topic[title.upper()]}) util.save_entry(title, body) body = markdown2.markdown(util.get_entry(title)) return render(request, 'encyclopedia/topic.html', { 'body': body, 'topic_name': title })
def save(request): if request.method == "POST": title = request.POST.get('title') body = request.POST.get('textarea') txt = "" c = 0 for i in body.split('\n'): if i == '\r' and body.split('\r')[c + 1] == '\n': continue txt += i c += 1 util.save_entry(title, txt) body = markdown2.markdown(util.get_entry(title)) return render(request, 'encyclopedia/topic.html', { 'body': body, 'topic_name': title })
def editpage(request, entry): title = entry if request.method == "POST": form = EditPageForm(request.POST) if form.is_valid(): entry = form.cleaned_data["entry"] #write entry to md file util.save_entry(title, entry) return HttpResponseRedirect("/wiki/" + title) else: content = util.get_entry(title) tempform = EditPageForm(initial={'entry': content}) return render(request, "encyclopedia/editpage.html", { "form": tempform, "title": title, "urlpost": "/editpage/" + title })
def index(request): if request.method == "POST": form = NewTaskForm(request.POST) if form.is_valid(): title = form.cleaned_data["title"] if util.get_entry(title) == None: entry = form.cleaned_data["entry"] #write entry to md file util.save_entry(title, entry) #return HttpResponse("Success:" + title + "<br>" + "<a href=" + "/" + ">Home</a>") return HttpResponseRedirect("/wiki/"+title) else: return HttpResponse("Error:" + title + " already exists<br>" + "<a href=" + "/" + ">Home</a>") else: return render(request, "tasks/add.html", { "form": form }) return render(request, "newpage/index.html", { "form": NewTaskForm() })
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})