aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunasSudo <runassudo@yingtongli.me>2017-09-06 08:46:44 +1000
committerRunasSudo <runassudo@yingtongli.me>2017-09-06 08:46:44 +1000
commit9d7471364219b277b172717475b5e212b27aae7e (patch)
treed7ae2b9587c81a9846a384f80b474a85de503178
parent5ac16464290d37b87cf1ea417a75befa163950b5 (diff)
Add multiple-response MCQsHEADmaster
-rw-r--r--pblive/data.py10
-rw-r--r--pblive/templates/question_mcq.html23
-rw-r--r--pblive/templates/question_mcq_admin.html2
3 files changed, 29 insertions, 6 deletions
diff --git a/pblive/data.py b/pblive/data.py
index f770042..917c38f 100644
--- a/pblive/data.py
+++ b/pblive/data.py
@@ -78,6 +78,16 @@ class LandingQuestion(Question):
class MCQQuestion(Question):
template = 'question_mcq.html'
template_admin = 'question_mcq_admin.html'
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+
+ self.maximum = kwargs.get('maximum', 1)
+
+ def load_dict(self, obj):
+ super().load_dict(obj)
+
+ self.maximum = obj.get('maximum', self.maximum)
class DrawQuestion(Question):
template = 'question_draw.html'
diff --git a/pblive/templates/question_mcq.html b/pblive/templates/question_mcq.html
index a833a1f..c319955 100644
--- a/pblive/templates/question_mcq.html
+++ b/pblive/templates/question_mcq.html
@@ -19,9 +19,22 @@
{% extends 'question.html' %}
{% block base %}
- <div>
- {% for answer in session.questions[question_num].answers %}
- <button class="ui button{% if answer == user.answers[question_num] %} primary{% endif %}" onclick="socket.emit('answer', {{ question_num }}, '{{ answer }}');">{{ answer }}</button>
- {% endfor %}
- </div>
+ {% if session.questions[question_num].maximum == 1 %}
+ <div>
+ {% for answer in session.questions[question_num].answers %}
+ <button class="ui button{% if answer in user.answers[question_num] %} primary{% endif %}" onclick="socket.emit('answer', {{ question_num }}, ['{{ answer }}']);">{{ answer }}</button>
+ {% endfor %}
+ </div>
+ {% else %}
+ <div class="ui form">
+ {% for answer in session.questions[question_num].answers %}
+ <div class="inline field">
+ <div class="ui checkbox">
+ <input type="checkbox" class="mcq_checkbox" data-answer="{{ answer }}" onchange="socket.emit('answer', {{ question_num }}, $('.mcq_checkbox:checked').map(function(i,e){return e.dataset.answer;}).get());">
+ <label>{{ answer }}</label>
+ </div>
+ </div>
+ {% endfor %}
+ </div>
+ {% endif %}
{% endblock %}
diff --git a/pblive/templates/question_mcq_admin.html b/pblive/templates/question_mcq_admin.html
index 1f885af..283f87c 100644
--- a/pblive/templates/question_mcq_admin.html
+++ b/pblive/templates/question_mcq_admin.html
@@ -25,7 +25,7 @@
<li style="line-height: 32px;">
{{ answer }}:
{% for _, user in data.users.items() %}
- {% if user.session == session and user.answers[question_num] == answer %}
+ {% if user.session == session and answer in user.answers[question_num] %}
<button class="ui button" style="background-color: {{ user.colour[1] }}; width: 32px; height: 32px; padding: 0 0;">{{ user.colour[0] }}</button>
{% endif %}
{% endfor %}
Contact (issues, pull requests, etc.) at git@yingtongli.me. Generated by cgit.