began adding addpost function
This commit is contained in:
parent
81c455f014
commit
c50d047233
15 changed files with 106 additions and 21 deletions
|
|
@ -4,7 +4,7 @@ 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 blog.models import Topic
|
||||
from blog.models import Topic, Tag, Blogpost
|
||||
|
||||
from markdownblog import settings
|
||||
|
||||
|
|
@ -15,16 +15,34 @@ def viewblog(request) -> HttpResponse:
|
|||
|
||||
@login_required
|
||||
def order(request):
|
||||
return None
|
||||
return render(request, 'blog/order.html')
|
||||
|
||||
|
||||
@login_required
|
||||
def addpost(request) -> HttpResponse:
|
||||
if request.method == 'POST':
|
||||
title = request.POST['title']
|
||||
markdown = request.POST['markdown']
|
||||
|
||||
tags = []
|
||||
|
||||
if 'tags' in request.POST and request.POST['tags'] != '':
|
||||
tags_str = request.POST['tags'].split(" ")
|
||||
for tag in tags_str:
|
||||
tags.append(Tag.objects.filter(name=tag)[0])
|
||||
|
||||
topicstr = request.POST['topic']
|
||||
topics = None if topicstr == "No topic" else Topic.objects.filter(name=topicstr)[0]
|
||||
|
||||
new_post = Blogpost.objects.create(title=title, topics=topics)
|
||||
new_post.tags.set(tags)
|
||||
|
||||
context = {'alltopics': Topic.objects.all().order_by('name').values()}
|
||||
return render(request, 'blog/addpost.html', context)
|
||||
|
||||
|
||||
def createmocks(request, n) -> HttpResponse:
|
||||
def createmocks(request, objtype, n) -> HttpResponse:
|
||||
|
||||
topics = TopicFactory.create_batch(n)
|
||||
|
||||
for topic in topics:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue