implemented mocking topics

This commit is contained in:
CDaut 2022-06-01 16:54:47 +02:00 committed by CDaut
parent f3297544f9
commit dfb3b30271
12 changed files with 169 additions and 16 deletions

View file

@ -1,10 +1,33 @@
from django.shortcuts import render
import random
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.shortcuts import render, redirect
from blog.factories import TopicFactory
from markdownblog import settings
# Create your views here.
def viewblog(request):
return render(request, 'blog/index.html')
def viewblog(request) -> HttpResponse:
return render(request, 'blog/index.html', {"debug": settings.DEBUG})
def addpost(request):
@login_required
def addpost(request) -> HttpResponse:
return render(request, 'blog/addpost.html')
def createmocks(request, n) -> HttpResponse:
topics = TopicFactory.create_batch(n)
for topic in topics:
topic.save()
while len(topics) > 1:
child = random.choice(topics)
topics.remove(child)
child.rootTopic = random.choice(topics)
child.save()
print('Created ' + str(n) + ' mock topics.')
return redirect("index")