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 = '
'; + post_str += ' | '; + post_str += '' + data.options[i][1] + ' | '; + post_str += '0 |
'; + post_str += ' | '; + post_str += '' + data.options[i][1] + ' | '; + post_str += '0 |