diff --git a/quest/consumers.py b/quest/consumers.py index ed84425..b28d095 100644 --- a/quest/consumers.py +++ b/quest/consumers.py @@ -40,7 +40,7 @@ class QuestConsumer(WebsocketConsumer): return self.events[event](self, data.get('data')) - def send(self, event, data): + def send(self, event, data={}): """ Overridden method. If a dictionary is provided, it is converted to JSON before sending it. diff --git a/quest/events.py b/quest/events.py index d382882..be3b9f2 100644 --- a/quest/events.py +++ b/quest/events.py @@ -154,10 +154,13 @@ def dice_post(socket, data): dice_roll=dice_roll, strict=form['diceStrict'], dice_challenge=form['diceChal'], - rolls_taken=form['diceRollsTaken'] + rolls_taken=form['diceRollsTaken'], + open=True, ) d.save() + socket.send('close_all_posts') + data = {} data['post_text'] = post_text data['post_type'] = 'dice' @@ -166,6 +169,42 @@ def dice_post(socket, data): socket.send('new_post', data) +def close_post(socket, data): + """ + Called when the QM closes an open post. + """ + post_id = data.get('post_id') + p = Post.objects.get(id=post_id) + if data.get('post_type') == 'dice': + p.dicecall.open = False + p.dicecall.save() + elif data.get('post_type') == 'poll': + p.poll.open = False + p.poll.save() + + data = {} + data['post_id'] = post_id + socket.send('close_post', data) + + +def open_post(socket, data): + """ + Called when the QM opens a closed post. + """ + post_id = data.get('post_id') + p = Post.objects.get(id=post_id) + if data.get('post_type') == 'dice': + p.dicecall.open = True + p.dicecall.save() + elif data.get('post_type') == 'poll': + p.poll.open = True + p.poll.save() + + data = {} + data['post_id'] = post_id + socket.send('open_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 18e2386..c5c4f71 100644 --- a/quest/jinja2/quest/quest.html +++ b/quest/jinja2/quest/quest.html @@ -34,9 +34,9 @@ {% if post.post_type == "text" %}