added QM text posting, fixed timezone
This commit is contained in:
parent
78820ac797
commit
3f073a9d03
|
@ -9,8 +9,9 @@ import types
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import bleach
|
import bleach
|
||||||
|
from django.utils.timezone import localtime
|
||||||
|
|
||||||
from quest.models import Message, Quest
|
from quest.models import Message, Quest, Post
|
||||||
|
|
||||||
def message(socket, data):
|
def message(socket, data):
|
||||||
"""
|
"""
|
||||||
|
@ -88,6 +89,35 @@ def message(socket, data):
|
||||||
socket.send('message', data)
|
socket.send('message', data)
|
||||||
|
|
||||||
|
|
||||||
|
def text_post(socket, data):
|
||||||
|
"""
|
||||||
|
Called when the QM creates a new text post.
|
||||||
|
"""
|
||||||
|
quest_id = data.get('quest_id')
|
||||||
|
text = data.get('text')
|
||||||
|
page_num = data.get('page_num')
|
||||||
|
|
||||||
|
# cleaning
|
||||||
|
text = bleach.clean(text.strip())
|
||||||
|
text = text.replace("\n", "<br>")
|
||||||
|
|
||||||
|
# handle image
|
||||||
|
|
||||||
|
p = Post(
|
||||||
|
quest=Quest.objects.get(id=quest_id),
|
||||||
|
page_num=page_num,
|
||||||
|
post_type='text',
|
||||||
|
post_text=text)
|
||||||
|
p.save()
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
data['text'] = 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)
|
||||||
|
|
||||||
|
|
||||||
events = {}
|
events = {}
|
||||||
for obj in dir():
|
for obj in dir():
|
||||||
if type(locals()[obj]) == types.FunctionType:
|
if type(locals()[obj]) == types.FunctionType:
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="{{ static('quest.js') }}"></script>
|
<script type="text/javascript" src="{{ static('quest.js') }}"></script>
|
||||||
{% if request.user == quest.owner %}
|
{% if request.user == quest.owner %}
|
||||||
{#<script type="text/javascript" src="{{ static('questQM.js') }}"></script>#}
|
<script type="text/javascript" src="{{ static('questQM.js') }}"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<script>window.onload = load;</script>
|
<script>window.onload = load;</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -41,6 +41,45 @@ socket.events['message'] = function(data) {
|
||||||
mbox.scrollTop = mbox.scrollHeight;
|
mbox.scrollTop = mbox.scrollHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
socket.events['new_post'] = function(data) {
|
||||||
|
//deactivate_post();
|
||||||
|
let qposts = document.getElementById('questPosts');
|
||||||
|
let post_str = '<div class="questPost ';
|
||||||
|
if (data.post_type == 'text') {
|
||||||
|
post_str += 'textPost">';
|
||||||
|
} else if (data.post_type == 'dice') {
|
||||||
|
post_str += 'dicePost active_post">';
|
||||||
|
} else if (data.post_type == 'poll') {
|
||||||
|
post_str += 'pollPost active_post">';
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
} else if (data.post_type == 'dice') {
|
||||||
|
post_str += '<h3>' + data.text + ' - Open</h3>';
|
||||||
|
} else if (data.post_type == 'poll') {
|
||||||
|
post_str += '<h3>' + data.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++) {
|
||||||
|
post_str += '<tr id="optionRow-' + data.options[i][0] + '">';
|
||||||
|
post_str += '<td class="pollCheckBox"><input type="checkbox" id="pollInput-' + data.options[i][0] + '" onchange="pollVote(' + data.post_id + ',' + data.options[i][0] + ')"/>';
|
||||||
|
post_str += '<label for="pollInput-' + data.options[i][0] + '"></label></td>';
|
||||||
|
post_str += '<td class="option_text">' + data.options[i][1] + '</td>';
|
||||||
|
post_str += '<td class="optionVotes">0</td></tr>';
|
||||||
|
}
|
||||||
|
post_str += '</table>';
|
||||||
|
if (data.allow_writein) {
|
||||||
|
post_str += '<div id="writeinContainer">';
|
||||||
|
post_str += 'Write-in: <input type="text" id="writeinInput" placeholder="Custom choice..." maxlength="200" /><br />';
|
||||||
|
post_str += '<input type="submit" id="writeinSubmit" value="Submit" onclick="submitWritein({{ quest_post[0] }});"/></div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post_str += '</div></div><br />';
|
||||||
|
qposts.innerHTML = qposts.innerHTML + post_str;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Helpers */
|
/* Helpers */
|
||||||
function padToTwo(number) {
|
function padToTwo(number) {
|
||||||
|
|
68
quest/static/questQM.js
Normal file
68
quest/static/questQM.js
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
socket.events['new_post'] = function(data) {
|
||||||
|
//deactivate_post();
|
||||||
|
let qposts = document.getElementById('questPosts');
|
||||||
|
let post_str = '<div class="questPost ';
|
||||||
|
if (data.post_type == 'text') {
|
||||||
|
post_str += 'textPost">';
|
||||||
|
} else if (data.post_type == 'dice') {
|
||||||
|
post_str += 'dicePost active_post">';
|
||||||
|
} else if (data.post_type == 'poll') {
|
||||||
|
post_str += 'pollPost active_post">';
|
||||||
|
}
|
||||||
|
post_str += '<div class="questPostMeta">' + data.date;
|
||||||
|
/* QM only */
|
||||||
|
if (data.post_type == 'text') {
|
||||||
|
post_str += '<br /><a href="javascript:void(0);" onclick="edit_post(\'' + data.post_id + '\')">Edit</a>';
|
||||||
|
post_str += '<a href="javascript:void(0);" id="savePost-' + data.post_id + '" onclick="save_post(\'' + data.post_id + '\')" style="display:none;">Save</a>';
|
||||||
|
} else if (data.post_type == 'dice' || data.post_type == 'poll') {
|
||||||
|
post_str += '<br /><a href="javascript:void(0);" id="close_post_id-' + data.post_id + '" onclick="close_post(' + data.post_id + ')">Close</a>';
|
||||||
|
post_str += '<a href="javascript:void(0);" id="open_post_id-' + data.post_id + '" onclick="open_post(' + data.post_id + ')" style="display:none;">Open</a>'
|
||||||
|
}
|
||||||
|
/* end QM only */
|
||||||
|
post_str += '</div><div class="questPostData" id="questPostData-' + data.post_id + '">';
|
||||||
|
if (data.post_type == 'text') {
|
||||||
|
post_str += data.text;
|
||||||
|
} else if (data.post_type == 'dice') {
|
||||||
|
post_str += '<h3>' + data.text + ' - Open</h3>';
|
||||||
|
} else if (data.post_type == 'poll') {
|
||||||
|
post_str += '<h3>' + data.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++) {
|
||||||
|
post_str += '<tr id="optionRow-' + data.options[i][0] + '">';
|
||||||
|
post_str += '<td class="pollCheckBox"><input type="checkbox" id="pollInput-' + data.options[i][0] + '" onchange="pollVote(' + data.post_id + ',' + data.options[i][0] + ')"/>';
|
||||||
|
post_str += '<label for="pollInput-' + data.options[i][0] + '"></label></td>';
|
||||||
|
post_str += '<td class="option_text">' + data.options[i][1] + '</td>';
|
||||||
|
post_str += '<td class="optionVotes">0</td></tr>';
|
||||||
|
}
|
||||||
|
post_str += '</table>';
|
||||||
|
if (data.allow_writein) {
|
||||||
|
post_str += '<div id="writeinContainer">';
|
||||||
|
post_str += 'Write-in: <input type="text" id="writeinInput" placeholder="Custom choice..." maxlength="200" /><br />';
|
||||||
|
post_str += '<input type="submit" id="writeinSubmit" value="Submit" onclick="submitWritein({{ quest_post[0] }});"/></div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post_str += '</div></div><br />';
|
||||||
|
qposts.innerHTML = qposts.innerHTML + post_str;
|
||||||
|
};
|
||||||
|
|
||||||
|
function makePost() {
|
||||||
|
let qparea = document.getElementById('postTextArea');
|
||||||
|
let text = qparea.value.trim();
|
||||||
|
qparea.value = '';
|
||||||
|
if (text == '') { return; }
|
||||||
|
socket.send('text_post', {text: text, page_num: page_num, quest_id: quest_id});
|
||||||
|
}
|
||||||
|
|
||||||
|
function openPostTab(event, modeName) {
|
||||||
|
let QMPostTabContent = document.getElementsByClassName("QMPostTabContent");
|
||||||
|
for (let i = 0; i < QMPostTabContent.length; i++) {
|
||||||
|
QMPostTabContent[i].style.display = "none";
|
||||||
|
}
|
||||||
|
let QMPostTab = document.getElementsByClassName("QMPostTab");
|
||||||
|
for (let i = 0; i < QMPostTab.length; i++) {
|
||||||
|
QMPostTab[i].className = QMPostTab[i].className.replace(" active", "");
|
||||||
|
}
|
||||||
|
document.getElementById(modeName).style.display = "block";
|
||||||
|
event.currentTarget.className += " active";
|
||||||
|
}
|
|
@ -119,7 +119,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'en-us'
|
||||||
|
|
||||||
TIME_ZONE = 'America/Chicago'
|
TIME_ZONE = 'America/New_York'
|
||||||
|
|
||||||
USE_I18N = False
|
USE_I18N = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user