2018-08-10 08:39:51 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
/create_quest app views.
|
|
|
|
"""
|
2018-08-13 07:02:14 -04:00
|
|
|
from django.contrib import messages
|
|
|
|
from django.shortcuts import redirect, render
|
|
|
|
|
|
|
|
from .forms import QuestForm, PostForm
|
2018-09-05 12:22:45 -04:00
|
|
|
from quest.models import Quest, Post, PageTitle
|
2018-08-10 08:39:51 -04:00
|
|
|
|
|
|
|
def index(request):
|
|
|
|
"""
|
|
|
|
The index page for creating new quests.
|
|
|
|
"""
|
2018-08-13 07:02:14 -04:00
|
|
|
if request.method == 'POST':
|
|
|
|
quest = Quest(owner=request.user)
|
|
|
|
quest_form = QuestForm(request.POST, instance=quest)
|
|
|
|
post = Post(post_type='text', page_num=1)
|
|
|
|
post_form = PostForm(request.POST, instance=post)
|
|
|
|
if all((quest_form.is_valid(), post_form.is_valid())):
|
|
|
|
quest.save()
|
|
|
|
post.quest = quest
|
|
|
|
post.save()
|
2018-09-05 12:22:45 -04:00
|
|
|
page = PageTitle(
|
|
|
|
quest=quest,
|
|
|
|
page_num=1,
|
|
|
|
title="Page 1"
|
|
|
|
)
|
|
|
|
page.save()
|
2018-08-13 07:02:14 -04:00
|
|
|
return redirect('quest:quest', quest_id=quest.id)
|
|
|
|
else:
|
|
|
|
quest_form = QuestForm()
|
|
|
|
post_form = PostForm()
|
|
|
|
context = {'quest_form': quest_form, 'post_form': post_form}
|
2018-08-10 08:39:51 -04:00
|
|
|
return render(request, 'create_quest/index.html', context)
|