30 lines
848 B
Python
30 lines
848 B
Python
#!/usr/bin/env python3
|
|
"""
|
|
/create_quest app views.
|
|
"""
|
|
from django.contrib import messages
|
|
from django.shortcuts import redirect, render
|
|
|
|
from .forms import QuestForm, PostForm
|
|
from quest.models import Quest, Post
|
|
|
|
def index(request):
|
|
"""
|
|
The index page for creating new quests.
|
|
"""
|
|
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()
|
|
return redirect('quest:quest', quest_id=quest.id)
|
|
else:
|
|
quest_form = QuestForm()
|
|
post_form = PostForm()
|
|
context = {'quest_form': quest_form, 'post_form': post_form}
|
|
return render(request, 'create_quest/index.html', context)
|