From fb7ffc4d78f4546123f9d034ff6b7e8e2c8127da Mon Sep 17 00:00:00 2001 From: iou1name Date: Mon, 24 Sep 2018 08:22:01 -0400 Subject: [PATCH] basic support for new pages --- quest/events.py | 15 +++++++++ quest/forms.py | 2 +- quest/jinja2/quest/quest.html | 57 ++++++++++++++++++++--------------- quest/views.py | 6 ++-- 4 files changed, 51 insertions(+), 29 deletions(-) diff --git a/quest/events.py b/quest/events.py index 8ca51e1..65e2423 100644 --- a/quest/events.py +++ b/quest/events.py @@ -406,6 +406,21 @@ def write_in(socket, data): socket.send('update_post', data) +def new_page(socket, data): + """ + Called when the QM creates a new page. + """ + title = data.get('page_title') + + quest = Quest.objects.get(id=socket.quest_id) + p = PageTitle( + quest=quest, + page_num=PageTitle.objects.filter(quest=quest).count() + 1, + title=title, + ) + p.save() + + events = {} for obj in dir(): if type(locals()[obj]) == types.FunctionType: diff --git a/quest/forms.py b/quest/forms.py index e57d1f1..f4d287f 100644 --- a/quest/forms.py +++ b/quest/forms.py @@ -37,7 +37,7 @@ class PollForm(forms.Form): continue self.fields[key] = forms.CharField(max_length=200) -class EditQuest(forms.Form): +class EditQuestForm(forms.Form): """ Form for the /edit_quest page. """ diff --git a/quest/jinja2/quest/quest.html b/quest/jinja2/quest/quest.html index bcf0e28..225feaf 100644 --- a/quest/jinja2/quest/quest.html +++ b/quest/jinja2/quest/quest.html @@ -46,13 +46,13 @@ {{ localtime(post.timestamp).strftime('%Y-%m-%d %H:%M') }} {% if request.user == quest.owner %} {% if post.post_type == "text" %} -
Edit +
Edit {% elif post.post_type == "dice" %} -
+
{% elif post.post_type == "poll" %} -
+
{% endif %} {% endif %} @@ -75,7 +75,7 @@ {% for option in poll_options.filter(poll=post.poll).order_by("id") %} - + {{ option.text }} @@ -85,8 +85,8 @@ {% if post.poll.open and post.poll.allow_writein %}
- Write-in:
- + Write-in:
+
{% endif %} {% endif %} @@ -101,27 +101,28 @@
  • Text
  • Dice
  • Poll
  • +
  • Page
  • -
    - +
    +
    + @@ -159,7 +166,7 @@ {% endfor %} {% endautoescape %} -
    +
    {% endblock %} diff --git a/quest/views.py b/quest/views.py index 9edcb89..129d2cc 100644 --- a/quest/views.py +++ b/quest/views.py @@ -6,7 +6,7 @@ from django.shortcuts import render, redirect from django.http import HttpResponse from .models import Quest, DiceRoll, PollOption, PollVote, PageTitle -from .forms import EditQuest +from .forms import EditQuestForm def index(request): """ @@ -22,7 +22,7 @@ def quest(request, quest_id, page_num=1): quest = Quest.objects.get(id=quest_id) pages = PageTitle.objects.filter(quest=quest).order_by('page_num') messages = quest.message_set.all() - posts = quest.post_set.all() + posts = quest.post_set.filter(page_num=page_num) dice_rolls = DiceRoll.objects.filter(dicecall__post__quest=quest) poll_options = PollOption.objects.filter(poll__post__quest=quest) poll_votes = PollVote.objects.filter(option__poll__post__quest=quest) @@ -39,7 +39,7 @@ def edit_quest(request, quest_id, page_num=1): if quest.owner != request.user: return redirect('quest:quest', quest_id=quest_id, page_num=page_num) if request.method == 'POST': - form = EditQuest(request.POST) + form = EditQuestForm(request.POST) if form.is_valid(): quest.anon_name = form.cleaned_data['anon_name'] quest.save()