added limited dice call posting
This commit is contained in:
parent
3f073a9d03
commit
3d0f1beadf
|
@ -12,6 +12,7 @@ import bleach
|
|||
from django.utils.timezone import localtime
|
||||
|
||||
from quest.models import Message, Quest, Post
|
||||
from quest.forms import DiceCallForm
|
||||
|
||||
def message(socket, data):
|
||||
"""
|
||||
|
@ -93,13 +94,14 @@ def text_post(socket, data):
|
|||
"""
|
||||
Called when the QM creates a new text post.
|
||||
"""
|
||||
# TODO: security
|
||||
quest_id = data.get('quest_id')
|
||||
text = data.get('text')
|
||||
post_text = data.get('text')
|
||||
page_num = data.get('page_num')
|
||||
|
||||
# cleaning
|
||||
text = bleach.clean(text.strip())
|
||||
text = text.replace("\n", "<br>")
|
||||
post_text = bleach.clean(post_text.strip())
|
||||
post_text = text.replace("\n", "<br>")
|
||||
|
||||
# handle image
|
||||
|
||||
|
@ -107,17 +109,46 @@ def text_post(socket, data):
|
|||
quest=Quest.objects.get(id=quest_id),
|
||||
page_num=page_num,
|
||||
post_type='text',
|
||||
post_text=text)
|
||||
post_text=post_text)
|
||||
p.save()
|
||||
|
||||
data = {}
|
||||
data['text'] = text
|
||||
data['post_text'] = post_text
|
||||
data['post_type'] = 'text'
|
||||
data['date'] = localtime(p.timestamp).strftime('%Y-%m-%d %H:%M')
|
||||
data['post_id'] = p.id
|
||||
socket.send('new_post', data)
|
||||
|
||||
|
||||
def dice_post(socket, data):
|
||||
"""
|
||||
Called when the QM makes a new dice post.
|
||||
"""
|
||||
quest_id = data.get('quest_id')
|
||||
page_num = data.get('page_num')
|
||||
form = DiceCallForm(data)
|
||||
if not form.is_valid():
|
||||
return # error message?
|
||||
|
||||
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 += "+"
|
||||
dice_roll += str(form.cleaned_data['diceMod'])
|
||||
|
||||
post_text = "Roll " + dice_roll
|
||||
if form.cleaned_data['diceChal']:
|
||||
post_text += " vs DC" + str(form.cleaned_data['diceChal'])
|
||||
|
||||
data = {}
|
||||
data['post_text'] = post_text
|
||||
data['post_type'] = 'dice'
|
||||
data['date'] = int(time.time())
|
||||
data['post_id'] = 1
|
||||
socket.send('new_post', data)
|
||||
|
||||
|
||||
events = {}
|
||||
for obj in dir():
|
||||
if type(locals()[obj]) == types.FunctionType:
|
||||
|
|
19
quest/forms.py
Normal file
19
quest/forms.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Form(s) for the quest page.
|
||||
"""
|
||||
from django import forms
|
||||
|
||||
class DiceCallForm(forms.Form):
|
||||
"""
|
||||
The form for the QM making dice calls.
|
||||
"""
|
||||
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)
|
||||
diceStrict = forms.BooleanField(required=False)
|
|
@ -15,8 +15,7 @@ h3 {
|
|||
|
||||
#questPane {
|
||||
padding-left: 5%;
|
||||
padding-right: 35%;
|
||||
width: 100%;
|
||||
width: 65%;
|
||||
}
|
||||
|
||||
.questPost {
|
||||
|
|
|
@ -55,11 +55,11 @@ socket.events['new_post'] = function(data) {
|
|||
post_str += '<div class="questPostMeta">' + data.date;
|
||||
post_str += '</div><div class="questPostData" id="questPostData-' + data.post_id + '">';
|
||||
if (data.post_type == 'text') {
|
||||
post_str += data.text;
|
||||
post_str += data.post_text;
|
||||
} else if (data.post_type == 'dice') {
|
||||
post_str += '<h3>' + data.text + ' - Open</h3>';
|
||||
post_str += '<h3>' + data.post_text + ' - Open</h3>';
|
||||
} else if (data.post_type == 'poll') {
|
||||
post_str += '<h3>' + data.text + ' - Open</h3>';
|
||||
post_str += '<h3>' + data.post_text + ' - Open</h3>';
|
||||
post_str += '<table class="poll" id="poll-' + data.post_id + '">';
|
||||
post_str += '<col/><col/><col/>';
|
||||
for (i = 0; i < data.options.length; i++) {
|
||||
|
|
|
@ -21,11 +21,11 @@ socket.events['new_post'] = function(data) {
|
|||
/* end QM only */
|
||||
post_str += '</div><div class="questPostData" id="questPostData-' + data.post_id + '">';
|
||||
if (data.post_type == 'text') {
|
||||
post_str += data.text;
|
||||
post_str += data.post_text;
|
||||
} else if (data.post_type == 'dice') {
|
||||
post_str += '<h3>' + data.text + ' - Open</h3>';
|
||||
post_str += '<h3>' + data.post_text + ' - Open</h3>';
|
||||
} else if (data.post_type == 'poll') {
|
||||
post_str += '<h3>' + data.text + ' - Open</h3>';
|
||||
post_str += '<h3>' + data.post_text + ' - Open</h3>';
|
||||
post_str += '<table class="poll" id="poll-' + data.post_id + '">';
|
||||
post_str += '<col/><col/><col/>';
|
||||
for (i = 0; i < data.options.length; i++) {
|
||||
|
@ -66,3 +66,14 @@ function openPostTab(event, modeName) {
|
|||
document.getElementById(modeName).style.display = "block";
|
||||
event.currentTarget.className += " active";
|
||||
}
|
||||
function form_post(form_id, emit_msg) {
|
||||
let formData = new FormData(document.getElementById(form_id));
|
||||
let obj = {};
|
||||
formData.forEach(function(value, key) {
|
||||
obj[key] = value;
|
||||
});
|
||||
obj.quest_id = quest_id;
|
||||
obj.page_num = page_num;
|
||||
socket.send(emit_msg, obj);
|
||||
document.getElementById(form_id).reset();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user