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 #} -

{{ post.post_test }} - {% if post.id == quest.open_post_id %}Open{% else %}Closed{% endif %}

+ {% elif post.post_type == "poll" %} +

{{ post.post_text }} - {% if post.id == quest.open_post_id %}Open{% else %}Closed{% endif %}

{# for option in options.get(post.id, []) %} @@ -109,7 +110,7 @@ Strict
DC: -
+
Rolls Taken:
diff --git a/quest/migrations/0007_dicecall.py b/quest/migrations/0007_dicecall.py new file mode 100644 index 0000000..1da2705 --- /dev/null +++ b/quest/migrations/0007_dicecall.py @@ -0,0 +1,25 @@ +# Generated by Django 2.1 on 2018-08-23 15:46 + +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('quest', '0006_auto_20180817_0921'), + ] + + operations = [ + migrations.CreateModel( + name='DiceCall', + fields=[ + ('post', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='quest.Post')), + ('dice_roll', models.CharField(max_length=9)), + ('strict', models.BooleanField()), + ('dice_challenge', models.IntegerField(blank=True, null=True, validators=[django.core.validators.MaxValueValidator(999), django.core.validators.MinValueValidator(1)])), + ('rolls_taken', models.IntegerField(blank=True, null=True, validators=[django.core.validators.MaxValueValidator(99), django.core.validators.MinValueValidator(1)])), + ], + ), + ] diff --git a/quest/models.py b/quest/models.py index 0a76838..f0f07a6 100644 --- a/quest/models.py +++ b/quest/models.py @@ -4,6 +4,7 @@ The main quest models. """ from django.db import models from django.conf import settings +from django.core.validators import MaxValueValidator, MinValueValidator class Quest(models.Model): """ @@ -25,11 +26,42 @@ class Post(models.Model): POST_TYPES = ( ('text', 'Text'), ('dice', 'Dice'), - ('poll', 'Poll')) + ('poll', 'Poll') + ) post_type = models.CharField(max_length=4, choices=POST_TYPES) post_text = models.TextField() timestamp = models.DateTimeField(auto_now=True) + +class DiceCall(models.Model): + """ + An object representing dice calls made by the QM. + """ + post = models.OneToOneField( + Post, + on_delete=models.CASCADE, + primary_key=True, + ) + dice_roll = models.CharField(max_length=9) + strict = models.BooleanField() + dice_challenge = models.IntegerField( + null=True, + blank=True, + validators=[ + MaxValueValidator(999), + MinValueValidator(1) + ] + ) + rolls_taken = models.IntegerField( + null=True, + blank=True, + validators=[ + MaxValueValidator(99), + MinValueValidator(1) + ] + ) + + class PageTitle(models.Model): """ Represents the title of a quest page. @@ -41,6 +73,7 @@ class PageTitle(models.Model): def __str__(self): return self.title + class Message(models.Model): """ Represents a chat message.