dicecalls get saved to database
This commit is contained in:
parent
3d0f1beadf
commit
1c1ed68d7b
|
@ -11,7 +11,7 @@ import random
|
||||||
import bleach
|
import bleach
|
||||||
from django.utils.timezone import localtime
|
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
|
from quest.forms import DiceCallForm
|
||||||
|
|
||||||
def message(socket, data):
|
def message(socket, data):
|
||||||
|
@ -129,23 +129,40 @@ def dice_post(socket, data):
|
||||||
form = DiceCallForm(data)
|
form = DiceCallForm(data)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return # error message?
|
return # error message?
|
||||||
|
form = form.cleaned_data
|
||||||
|
|
||||||
dice_roll = str(form.cleaned_data['diceNum']) + "d"
|
dice_roll = str(form['diceNum']) + "d"
|
||||||
dice_roll += str(form.cleaned_data['diceSides'])
|
dice_roll += str(form['diceSides'])
|
||||||
if form.cleaned_data['diceMod']:
|
if form['diceMod']:
|
||||||
if form.cleaned_data['diceMod'] > 0:
|
if form['diceMod'] > 0:
|
||||||
dice_roll += "+"
|
dice_roll += "+"
|
||||||
dice_roll += str(form.cleaned_data['diceMod'])
|
dice_roll += str(form['diceMod'])
|
||||||
|
|
||||||
post_text = "Roll " + dice_roll
|
post_text = "Roll " + dice_roll
|
||||||
if form.cleaned_data['diceChal']:
|
if form['diceChal']:
|
||||||
post_text += " vs DC" + str(form.cleaned_data['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 = {}
|
||||||
data['post_text'] = post_text
|
data['post_text'] = post_text
|
||||||
data['post_type'] = 'dice'
|
data['post_type'] = 'dice'
|
||||||
data['date'] = int(time.time())
|
data['date'] = localtime(p.timestamp).strftime('%Y-%m-%d %H:%M')
|
||||||
data['post_id'] = 1
|
data['post_id'] = p.id
|
||||||
socket.send('new_post', data)
|
socket.send('new_post', data)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,10 @@ class DiceCallForm(forms.Form):
|
||||||
"""
|
"""
|
||||||
diceNum = forms.IntegerField(min_value=1, max_value=99)
|
diceNum = forms.IntegerField(min_value=1, max_value=99)
|
||||||
diceSides = 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,
|
diceMod = forms.IntegerField(
|
||||||
required=False)
|
min_value=-999, max_value=999, required=False)
|
||||||
diceChal = forms.IntegerField(min_value=1, max_value=99,
|
diceChal = forms.IntegerField(
|
||||||
required=False)
|
min_value=1, max_value=999, required=False)
|
||||||
diceRollsTaken = forms.IntegerField(min_value=1, max_value=99,
|
diceRollsTaken = forms.IntegerField(
|
||||||
required=False)
|
min_value=1, max_value=99, required=False)
|
||||||
diceStrict = forms.BooleanField(required=False)
|
diceStrict = forms.BooleanField(required=False)
|
||||||
|
|
|
@ -62,7 +62,8 @@
|
||||||
<b>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 %}</b>
|
<b>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 %}</b>
|
||||||
</div>
|
</div>
|
||||||
{% endfor #}
|
{% endfor #}
|
||||||
<h3>{{ post.post_test }} - {% if post.id == quest.open_post_id %}Open{% else %}Closed{% endif %}</h3>
|
{% elif post.post_type == "poll" %}
|
||||||
|
<h3>{{ post.post_text }} - {% if post.id == quest.open_post_id %}Open{% else %}Closed{% endif %}</h3>
|
||||||
<table class="poll" id="poll-{{ post.id }}">
|
<table class="poll" id="poll-{{ post.id }}">
|
||||||
{# for option in options.get(post.id, []) %}
|
{# for option in options.get(post.id, []) %}
|
||||||
<tr id="optionRow-{{ option[0] }}">
|
<tr id="optionRow-{{ option[0] }}">
|
||||||
|
@ -109,7 +110,7 @@
|
||||||
<span class="tooltip" title="Only take matching rolls.">Strict</span><br />
|
<span class="tooltip" title="Only take matching rolls.">Strict</span><br />
|
||||||
<input type="checkbox" onclick="document.getElementById('diceChal').disabled=!this.checked;"/>
|
<input type="checkbox" onclick="document.getElementById('diceChal').disabled=!this.checked;"/>
|
||||||
<span class="tooltip" title="Dice challenge">DC:</span>
|
<span class="tooltip" title="Dice challenge">DC:</span>
|
||||||
<input type="number" name="diceChal" id="diceChal" min="1" max="99" disabled/><br />
|
<input type="number" name="diceChal" id="diceChal" min="1" max="999" disabled/><br />
|
||||||
<input type="checkbox" onclick="document.getElementById('diceRollsTaken').disabled=!this.checked;"/>
|
<input type="checkbox" onclick="document.getElementById('diceRollsTaken').disabled=!this.checked;"/>
|
||||||
<span class="tooltip" title="Automatically close the dice call after this many rolls have been made.">Rolls Taken:</span>
|
<span class="tooltip" title="Automatically close the dice call after this many rolls have been made.">Rolls Taken:</span>
|
||||||
<input type="number" name="diceRollsTaken" id="diceRollsTaken" min="1" max="99" disabled/><br />
|
<input type="number" name="diceRollsTaken" id="diceRollsTaken" min="1" max="99" disabled/><br />
|
||||||
|
|
25
quest/migrations/0007_dicecall.py
Normal file
25
quest/migrations/0007_dicecall.py
Normal file
|
@ -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)])),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -4,6 +4,7 @@ The main quest models.
|
||||||
"""
|
"""
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||||
|
|
||||||
class Quest(models.Model):
|
class Quest(models.Model):
|
||||||
"""
|
"""
|
||||||
|
@ -25,11 +26,42 @@ class Post(models.Model):
|
||||||
POST_TYPES = (
|
POST_TYPES = (
|
||||||
('text', 'Text'),
|
('text', 'Text'),
|
||||||
('dice', 'Dice'),
|
('dice', 'Dice'),
|
||||||
('poll', 'Poll'))
|
('poll', 'Poll')
|
||||||
|
)
|
||||||
post_type = models.CharField(max_length=4, choices=POST_TYPES)
|
post_type = models.CharField(max_length=4, choices=POST_TYPES)
|
||||||
post_text = models.TextField()
|
post_text = models.TextField()
|
||||||
timestamp = models.DateTimeField(auto_now=True)
|
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):
|
class PageTitle(models.Model):
|
||||||
"""
|
"""
|
||||||
Represents the title of a quest page.
|
Represents the title of a quest page.
|
||||||
|
@ -41,6 +73,7 @@ class PageTitle(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
|
||||||
class Message(models.Model):
|
class Message(models.Model):
|
||||||
"""
|
"""
|
||||||
Represents a chat message.
|
Represents a chat message.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user