new topics can now be created
This commit is contained in:
parent
ee7c359d5b
commit
c71b06ac9b
4 changed files with 41 additions and 1 deletions
|
|
@ -1,9 +1,10 @@
|
|||
from blog.views import viewblog, addpost, order, index, createmocks, edit
|
||||
from blog.views import viewblog, addpost, order, index, createmocks, edit, addtopic
|
||||
from django.urls import path
|
||||
|
||||
urlpatterns = [
|
||||
path('', index, name="index"),
|
||||
path('manage/addpost', addpost, name='addpost'),
|
||||
path('manage/addtopic', addtopic, name='addtopic'),
|
||||
path('manage/order', order, name='order'),
|
||||
path('manage/edit/<int:id>/', edit, name='editpost'),
|
||||
path('mock/<str:objtype>/<int:n>/', createmocks, name='mock'),
|
||||
|
|
|
|||
|
|
@ -159,3 +159,14 @@ def createmocks(request, objtype, n) -> HttpResponse:
|
|||
|
||||
print('Created ' + str(n) + ' mock topics.')
|
||||
return redirect("index")
|
||||
|
||||
|
||||
@login_required
|
||||
def addtopic(request):
|
||||
context = {'roottopics': Topic.objects.all().filter(rootTopic=None), 'allposts': Blogpost.objects.all()}
|
||||
|
||||
if request.method == 'POST':
|
||||
topictitle = request.POST['title']
|
||||
Topic.objects.get_or_create(name=topictitle)
|
||||
|
||||
return render(request, 'blog/addtopic.html', context)
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@
|
|||
{% if user.is_authenticated %}
|
||||
<li class="no-liststyle"><a class="waves-effect" href="{% url 'addpost' %}"><i
|
||||
class="material-icons">add</i>New post</a></li>
|
||||
<li class="no-liststyle"><a class="waves-effect" href="{% url 'addtopic' %}"><i
|
||||
class="material-icons">add</i>New topic</a></li>
|
||||
<li class="no-liststyle"><a class="waves-effect" href="{% url 'order' %}"><i
|
||||
class="material-icons">reorder</i>Manage posts</a>
|
||||
</li>
|
||||
|
|
|
|||
26
markdownblog/markdownblog/templates/blog/addtopic.html
Normal file
26
markdownblog/markdownblog/templates/blog/addtopic.html
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{% extends 'base/base.html' %}
|
||||
{% load static %}
|
||||
{% block title %}
|
||||
New Topic
|
||||
{% endblock %}
|
||||
{% block includehere %}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<div class="col s12">
|
||||
<form action="{% url 'addtopic' %}" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<div class="row">
|
||||
<div class="col s6" style="margin-top: 3em;">
|
||||
<label>
|
||||
Topic title
|
||||
<input type="text" name="title">
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="waves-effect waves-light btn">
|
||||
<i class="material-icons left">add</i>
|
||||
Create topic
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue