diff --git a/quest/events.py b/quest/events.py index ea92787..d382882 100644 --- a/quest/events.py +++ b/quest/events.py @@ -11,7 +11,7 @@ import random import bleach from django.utils.timezone import localtime -from quest.models import Message, Quest, Post +from quest.models import Message, Quest, Post, DiceCall from quest.forms import DiceCallForm def message(socket, data): @@ -129,23 +129,40 @@ def dice_post(socket, data): form = DiceCallForm(data) if not form.is_valid(): return # error message? + form = form.cleaned_data - dice_roll = str(form.cleaned_data['diceNum']) + "d" - dice_roll += str(form.cleaned_data['diceSides']) - if form.cleaned_data['diceMod']: - if form.cleaned_data['diceMod'] > 0: + dice_roll = str(form['diceNum']) + "d" + dice_roll += str(form['diceSides']) + if form['diceMod']: + if form['diceMod'] > 0: dice_roll += "+" - dice_roll += str(form.cleaned_data['diceMod']) + dice_roll += str(form['diceMod']) post_text = "Roll " + dice_roll - if form.cleaned_data['diceChal']: - post_text += " vs DC" + str(form.cleaned_data['diceChal']) + if form['diceChal']: + post_text += " vs DC" + str(form['diceChal']) + + p = Post( + quest=Quest.objects.get(id=quest_id), + page_num=page_num, + post_type='dice', + post_text=post_text + ) + p.save() + d = DiceCall( + post=p, + dice_roll=dice_roll, + strict=form['diceStrict'], + dice_challenge=form['diceChal'], + rolls_taken=form['diceRollsTaken'] + ) + d.save() data = {} data['post_text'] = post_text data['post_type'] = 'dice' - data['date'] = int(time.time()) - data['post_id'] = 1 + data['date'] = localtime(p.timestamp).strftime('%Y-%m-%d %H:%M') + data['post_id'] = p.id socket.send('new_post', data) diff --git a/quest/forms.py b/quest/forms.py index 53f8455..463fef6 100644 --- a/quest/forms.py +++ b/quest/forms.py @@ -10,10 +10,10 @@ class DiceCallForm(forms.Form): """ diceNum = forms.IntegerField(min_value=1, max_value=99) diceSides = forms.IntegerField(min_value=1, max_value=99) - diceMod = forms.IntegerField(min_value=-999, max_value=999, - required=False) - diceChal = forms.IntegerField(min_value=1, max_value=99, - required=False) - diceRollsTaken = forms.IntegerField(min_value=1, max_value=99, - required=False) + diceMod = forms.IntegerField( + min_value=-999, max_value=999, required=False) + diceChal = forms.IntegerField( + min_value=1, max_value=999, required=False) + diceRollsTaken = forms.IntegerField( + min_value=1, max_value=99, required=False) diceStrict = forms.BooleanField(required=False) diff --git a/quest/jinja2/quest/quest.html b/quest/jinja2/quest/quest.html index 04a3579..18e2386 100644 --- a/quest/jinja2/quest/quest.html +++ b/quest/jinja2/quest/quest.html @@ -62,7 +62,8 @@ Rolled {{ dice_roll[4] }} = {{ dice_roll[5] }} ({{ dice_roll[3] }}){% if post.id|dice_chal != 0 %} - {% if dice_roll[5] >= post.id|dice_chal %}Pass{% else %}Fail{% endif %}{% endif %} {% endfor #} -