diff --git a/create_quest/forms.py b/create_quest/forms.py index dbdaa9b..8cdc7e2 100644 --- a/create_quest/forms.py +++ b/create_quest/forms.py @@ -4,7 +4,7 @@ Form(s) for the create_quest page. """ from django import forms -from quest.models import Quest, Post, PageTitle +from quest.models import Quest, Post class QuestForm(forms.ModelForm): """ diff --git a/create_quest/views.py b/create_quest/views.py index 2881cf9..00e5445 100644 --- a/create_quest/views.py +++ b/create_quest/views.py @@ -6,7 +6,7 @@ from django.contrib import messages from django.shortcuts import redirect, render from .forms import QuestForm, PostForm -from quest.models import Quest, Post, PageTitle +from quest.models import Quest, Post, Page def index(request): """ @@ -16,18 +16,19 @@ def index(request): # TODO: clean the post body quest = Quest(owner=request.user) quest_form = QuestForm(request.POST, instance=quest) - post = Post(post_type='text', page_num=1) + post = Post(post_type='text') post_form = PostForm(request.POST, instance=post) if all((quest_form.is_valid(), post_form.is_valid())): quest.save() - post.quest = quest - post.save() - page = PageTitle( + page = Page( quest=quest, page_num=1, title="Page 1" ) page.save() + post.quest = quest + post.page = page + post.save() return redirect('quest:quest', quest_id=quest.id) else: quest_form = QuestForm() diff --git a/jinja2/base.html b/jinja2/base.html index 32d855f..bc6ac8c 100644 --- a/jinja2/base.html +++ b/jinja2/base.html @@ -1,3 +1,4 @@ +{% set vars = {} %}
diff --git a/quest/events.py b/quest/events.py index 0e5db02..dfccded 100644 --- a/quest/events.py +++ b/quest/events.py @@ -154,9 +154,10 @@ def text_post(socket, data): # handle image + quest = Quest.objects.get(id=socket.quest_id) p = Post( - quest=Quest.objects.get(id=socket.quest_id), - page_num=page_num, + quest=quest, + page=Page.objects.get(quest=quest, page_num=page_num), post_type='text', post_text=post_text) p.save() @@ -196,10 +197,11 @@ def dice_post(socket, data): post_text = "Roll " + dice_roll if form['diceChal']: post_text += " vs DC" + str(form['diceChal']) - + + quest = Quest.objects.get(id=socket.quest_id) p = Post( - quest=Quest.objects.get(id=socket.quest_id), - page_num=page_num, + quest=quest, + page=Page.objects.get(quest=quest, page_num=page_num), post_type='dice', post_text=post_text ) @@ -232,9 +234,10 @@ def poll_post(socket, data): return # error message? form = form.cleaned_data + quest=Quest.objects.get(id=socket.quest_id) p = Post( - quest=Quest.objects.get(id=socket.quest_id), - page_num=page_num, + quest=quest, + page=Page.objects.get(quest=quest, page_num=page_num), post_type='poll', post_text="Poll" ) @@ -412,19 +415,39 @@ def new_page(socket, data): Called when the QM creates a new page. """ title = data.get('page_title') + appendix = bool(data.get('appendix')) quest = Quest.objects.get(id=socket.quest_id) - p = PageTitle( + if appendix: + page = Page.objects.filter( + quest=quest, + appendix=True + ).order_by('page_num').last() + if page: + page_num = chr(ord(page.page_num)+1) + else: + page_num = 'a' + else: + page_num = Page.objects.filter( + quest=quest, + appendix=False + ).order_by('page_num').last().page_num + 1 + p = Page( quest=quest, - page_num=PageTitle.objects.filter(quest=quest).count() + 1, + page_num=page_num, title=title, + appendix=appendix, ) p.save() data = {} data['page_num'] = p.page_num data['title'] = title - data['url'] = reverse('quest:quest', args=[socket.quest_id, p.page_num]) + if appendix: + data['appendix'] = True + else: + data['appendix'] = False + data['url'] = reverse('quest:quest', args=[socket.quest_id, p.page_num]) socket.send('new_page', data) diff --git a/quest/jinja2/quest/quest.html b/quest/jinja2/quest/quest.html index 764b365..b50d6f3 100644 --- a/quest/jinja2/quest/quest.html +++ b/quest/jinja2/quest/quest.html @@ -23,9 +23,18 @@ {% endif %}