new topics can now be created

This commit is contained in:
CDaut 2022-06-25 19:07:24 +02:00 committed by CDaut
parent ee7c359d5b
commit c71b06ac9b
4 changed files with 41 additions and 1 deletions

View file

@ -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 from django.urls import path
urlpatterns = [ urlpatterns = [
path('', index, name="index"), path('', index, name="index"),
path('manage/addpost', addpost, name='addpost'), path('manage/addpost', addpost, name='addpost'),
path('manage/addtopic', addtopic, name='addtopic'),
path('manage/order', order, name='order'), path('manage/order', order, name='order'),
path('manage/edit/<int:id>/', edit, name='editpost'), path('manage/edit/<int:id>/', edit, name='editpost'),
path('mock/<str:objtype>/<int:n>/', createmocks, name='mock'), path('mock/<str:objtype>/<int:n>/', createmocks, name='mock'),

View file

@ -159,3 +159,14 @@ def createmocks(request, objtype, n) -> HttpResponse:
print('Created ' + str(n) + ' mock topics.') print('Created ' + str(n) + ' mock topics.')
return redirect("index") 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)

View file

@ -51,6 +51,8 @@
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li class="no-liststyle"><a class="waves-effect" href="{% url 'addpost' %}"><i <li class="no-liststyle"><a class="waves-effect" href="{% url 'addpost' %}"><i
class="material-icons">add</i>New post</a></li> 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 <li class="no-liststyle"><a class="waves-effect" href="{% url 'order' %}"><i
class="material-icons">reorder</i>Manage posts</a> class="material-icons">reorder</i>Manage posts</a>
</li> </li>

View 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 %}