diff --git a/quest/events.py b/quest/events.py index 77d9839..ac18b23 100644 --- a/quest/events.py +++ b/quest/events.py @@ -9,8 +9,9 @@ import types import random 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): """ @@ -88,6 +89,35 @@ def message(socket, 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", "
") + + # 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 = {} for obj in dir(): if type(locals()[obj]) == types.FunctionType: diff --git a/quest/jinja2/quest/quest.html b/quest/jinja2/quest/quest.html index ffb1d0b..04a3579 100644 --- a/quest/jinja2/quest/quest.html +++ b/quest/jinja2/quest/quest.html @@ -9,7 +9,7 @@ {% if request.user == quest.owner %} - {##} + {% endif %} {% endblock %} diff --git a/quest/static/quest.js b/quest/static/quest.js index a859fcd..01bd9ca 100644 --- a/quest/static/quest.js +++ b/quest/static/quest.js @@ -41,6 +41,45 @@ socket.events['message'] = function(data) { mbox.scrollTop = mbox.scrollHeight; } } +socket.events['new_post'] = function(data) { + //deactivate_post(); + let qposts = document.getElementById('questPosts'); + let post_str = '
'; + } else if (data.post_type == 'dice') { + post_str += 'dicePost active_post">'; + } else if (data.post_type == 'poll') { + post_str += 'pollPost active_post">'; + } + post_str += '
' + data.date; + post_str += '
'; + if (data.post_type == 'text') { + post_str += data.text; + } else if (data.post_type == 'dice') { + post_str += '

' + data.text + ' - Open

'; + } else if (data.post_type == 'poll') { + post_str += '

' + data.text + ' - Open

'; + post_str += ''; + post_str += ''; + for (i = 0; i < data.options.length; i++) { + post_str += ''; + post_str += ''; + post_str += ''; + post_str += ''; + } + post_str += '
'; + post_str += '' + data.options[i][1] + '0
'; + if (data.allow_writein) { + post_str += '
'; + post_str += 'Write-in:
'; + post_str += '
'; + } + } + post_str += '

'; + qposts.innerHTML = qposts.innerHTML + post_str; +}; + /* Helpers */ function padToTwo(number) { diff --git a/quest/static/questQM.js b/quest/static/questQM.js new file mode 100644 index 0000000..435efd8 --- /dev/null +++ b/quest/static/questQM.js @@ -0,0 +1,68 @@ +socket.events['new_post'] = function(data) { + //deactivate_post(); + let qposts = document.getElementById('questPosts'); + let post_str = '
'; + } else if (data.post_type == 'dice') { + post_str += 'dicePost active_post">'; + } else if (data.post_type == 'poll') { + post_str += 'pollPost active_post">'; + } + post_str += '
' + data.date; + /* QM only */ + if (data.post_type == 'text') { + post_str += '
Edit'; + post_str += ''; + } else if (data.post_type == 'dice' || data.post_type == 'poll') { + post_str += '
Close'; + post_str += '' + } + /* end QM only */ + post_str += '
'; + if (data.post_type == 'text') { + post_str += data.text; + } else if (data.post_type == 'dice') { + post_str += '

' + data.text + ' - Open

'; + } else if (data.post_type == 'poll') { + post_str += '

' + data.text + ' - Open

'; + post_str += ''; + post_str += ''; + for (i = 0; i < data.options.length; i++) { + post_str += ''; + post_str += ''; + post_str += ''; + post_str += ''; + } + post_str += '
'; + post_str += '' + data.options[i][1] + '0
'; + if (data.allow_writein) { + post_str += '
'; + post_str += 'Write-in:
'; + post_str += '
'; + } + } + post_str += '

'; + 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"; +} diff --git a/titivillus/settings.py b/titivillus/settings.py index b54c630..f3a0906 100644 --- a/titivillus/settings.py +++ b/titivillus/settings.py @@ -119,7 +119,7 @@ AUTH_PASSWORD_VALIDATORS = [ LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'America/Chicago' +TIME_ZONE = 'America/New_York' USE_I18N = False