Beispiel #1
0
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))
        })
Beispiel #2
0
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
    })
Beispiel #3
0
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))
    })
Beispiel #4
0
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
    })
Beispiel #5
0
def edit(request, title):
    content = util.get_entry(title)
    data = {
        'title': title,
        'content': content,
    }
    return render(request, "encyclopedia/create.html", {
        "form": util.CreateEntryForm(data),
    })
Beispiel #6
0
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')
Beispiel #7
0
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
			})
Beispiel #8
0
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.')
Beispiel #9
0
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
        })
Beispiel #10
0
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)
Beispiel #11
0
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
        })
Beispiel #12
0
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
        })
Beispiel #13
0
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
        })
Beispiel #14
0
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()
        })
Beispiel #15
0
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})