removed testing code

This commit is contained in:
CDaut 2022-06-25 21:05:42 +02:00 committed by CDaut
parent 4436bd2058
commit c9e97da9e9
3 changed files with 42 additions and 42 deletions

View file

@ -1,24 +1,24 @@
import factory
from blog.models import Topic, Blogpost, Tag
class TopicFactory(factory.Factory):
class Meta:
model = Topic
name = factory.Faker("word")
numbered = False
class PostFactory(factory.Factory):
class Meta:
model = Blogpost
title = factory.Faker("word")
tags = Tag.objects.all()[0] if len(Tag.objects.all()) != 0 else None
if len(Topic.objects.all()) == 0:
TopicFactory.create_batch(10)
topics = Topic.objects.all()[0] if len(Topic.objects.all()) != 0 else None
mdfile = "/tmp/test.md"
# import factory
#
# from blog.models import Topic, Blogpost, Tag
#
#
# class TopicFactory(factory.Factory):
# class Meta:
# model = Topic
#
# name = factory.Faker("word")
# numbered = False
#
#
# class PostFactory(factory.Factory):
# class Meta:
# model = Blogpost
#
# title = factory.Faker("word")
# tags = Tag.objects.all()[0] if len(Tag.objects.all()) != 0 else None
# if len(Topic.objects.all()) == 0:
# TopicFactory.create_batch(10)
# topics = Topic.objects.all()[0] if len(Topic.objects.all()) != 0 else None
#
# mdfile = "/tmp/test.md"

View file

@ -1,4 +1,4 @@
from blog.views import viewblog, addpost, order, index, createmocks, edit, addtopic
from blog.views import viewblog, addpost, order, index, edit, addtopic#, createmocks
from django.urls import path
urlpatterns = [
@ -7,6 +7,6 @@ urlpatterns = [
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'),
#path('mock/<str:objtype>/<int:n>/', createmocks, name='mock'),
path('read/<str:title>', viewblog, name='readpost'),
]

View file

@ -8,7 +8,7 @@ from django.contrib.auth.decorators import login_required
from django.db import IntegrityError
from django.http import HttpResponse
from django.shortcuts import render, redirect
from blog.factories import TopicFactory
#from blog.factories import TopicFactory
from blog.models import Topic, Tag, Blogpost
from django.template import Template, Context
from django.views.decorators.csrf import csrf_exempt
@ -144,21 +144,21 @@ def addpost(request) -> HttpResponse:
return render(request, 'blog/addpost.html', context)
@login_required
def createmocks(request, objtype, 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")
# @login_required
# def createmocks(request, objtype, 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")
@login_required