post creation now saves markdown files
This commit is contained in:
parent
01ed26a939
commit
ead8a3a2ef
3 changed files with 16 additions and 6 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
import random
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
|
@ -40,14 +41,19 @@ def addpost(request) -> HttpResponse:
|
|||
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])
|
||||
tags.append(Tag.objects.get_or_create(name=tag))
|
||||
|
||||
topicstr = request.POST['topic']
|
||||
topics = None if topicstr == "No topic" else Topic.objects.filter(name=topicstr)[0]
|
||||
topicid = request.POST['topic']
|
||||
topic = None if topicid == "No topic" else Topic.objects.get(pk=topicid)
|
||||
|
||||
new_post = Blogpost.objects.create(title=title, topics=topics)
|
||||
new_post = Blogpost.objects.create(title=title, topic=topic)
|
||||
new_post.tags.set(tags)
|
||||
|
||||
filepath = os.path.join(os.environ.get("MD_FILE_PATH"), title + ".md")
|
||||
with open(filepath, "w+") as mdfile:
|
||||
mdfile.write(markdown)
|
||||
mdfile.close()
|
||||
|
||||
context = {'alltopics': Topic.objects.all().order_by('name').values()}
|
||||
return render(request, 'blog/addpost.html', context)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue