Commit 00fb2cc2 by Xavier Antoviaque

Display quizzes questions & radio selections (both types)

parent bf9c05ec
...@@ -54,7 +54,7 @@ class AnswerBlock(XBlock): ...@@ -54,7 +54,7 @@ class AnswerBlock(XBlock):
Answer._meta.get_field('student_input').max_length, Answer._meta.get_field('student_input').max_length,
self.student_input) self.student_input)
else: else:
html = u'<blockquote class="answer read_only">{}</div>'.format(self.student_input) html = u'<blockquote class="answer read_only">{}</blockquote>'.format(self.student_input)
fragment = Fragment(html) fragment = Fragment(html)
fragment.add_css(load_resource('static/css/answer.css')) fragment.add_css(load_resource('static/css/answer.css'))
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
import logging import logging
from xblock.core import XBlock from xblock.core import XBlock
from xblock.fields import Any, List, Scope, String from xblock.fields import List, Scope, String
from xblock.fragment import Fragment from xblock.fragment import Fragment
from .utils import load_resource from .utils import load_resource, render_template
# Globals ########################################################### # Globals ###########################################################
...@@ -37,17 +37,14 @@ class QuizzBlock(XBlock): ...@@ -37,17 +37,14 @@ class QuizzBlock(XBlock):
""" """
TODO: Description TODO: Description
""" """
type = String(help="Type of quizz", scope=Scope.content, default="yes-no-unsure")
question = String(help="Question to ask the student", scope=Scope.content, default="") question = String(help="Question to ask the student", scope=Scope.content, default="")
type = String(help="Type of quizz", scope=Scope.content, default="yes-no-unsure")
low = String(help="Label for low ratings", scope=Scope.content, default="Less")
high = String(help="Label for high ratings", scope=Scope.content, default="More")
tip = String(help="Mentoring tip to provide if needed", scope=Scope.content, default="") tip = String(help="Mentoring tip to provide if needed", scope=Scope.content, default="")
tip_display = List(help="List of answers to display the tip for", scope=Scope.content, default=None) tip_display = List(help="List of choices to display the tip for", scope=Scope.content, default=None)
reject = List(help="List of answers to reject", scope=Scope.content, default=None) reject = List(help="List of choices to reject", scope=Scope.content, default=None)
student_input = Any(help="Last input submitted by the student", default="", scope=Scope.user_state) student_choice = String(help="Last input submitted by the student", default="", scope=Scope.user_state)
has_children = True
def __init__(self, *args, **kwargs):
super(QuizzBlock, self).__init__(*args, **kwargs)
# TODO
@classmethod @classmethod
def parse_xml(cls, node, runtime, keys): def parse_xml(cls, node, runtime, keys):
...@@ -63,6 +60,10 @@ class QuizzBlock(XBlock): ...@@ -63,6 +60,10 @@ class QuizzBlock(XBlock):
else: else:
block.runtime.add_node_as_child(block, child) block.runtime.add_node_as_child(block, child)
for name, value in node.items():
if name in block.fields:
setattr(block, name, value)
return block return block
def student_view(self, context=None): # pylint: disable=W0613 def student_view(self, context=None): # pylint: disable=W0613
...@@ -70,7 +71,15 @@ class QuizzBlock(XBlock): ...@@ -70,7 +71,15 @@ class QuizzBlock(XBlock):
return Fragment(u"<p>I can only appear inside mentoring blocks.</p>") return Fragment(u"<p>I can only appear inside mentoring blocks.</p>")
def mentoring_view(self, context=None): def mentoring_view(self, context=None):
fragment = Fragment(u'<h2>Quizz</h2>') # TODO if self.type not in ('yes-no-unsure', 'rating'):
raise ValueError, u'Invalid value for QuizzBlock.type: `{}`'.format(self.type)
template_path = 'static/html/quizz_{}.html'.format(self.type)
html = render_template(template_path, {
'self': self,
})
fragment = Fragment(html)
fragment.add_css(load_resource('static/css/quizz.css')) fragment.add_css(load_resource('static/css/quizz.css'))
fragment.add_javascript(load_resource('static/js/quizz.js')) fragment.add_javascript(load_resource('static/js/quizz.js'))
fragment.initialize_js('QuizzBlock') fragment.initialize_js('QuizzBlock')
......
<fieldset class="rating">
<legend>{{ self.question }}</legend>
<div class="choices">
<span class="low">{{ self.low }}</span>
<span class="choice">
<label><input type="radio" name="{{ self.name }}" value="1"{% if self.student_choice == '1' %} checked{% endif %}></label>
</span>
<span class="choice">
<label><input type="radio" name="{{ self.name }}" value="2"{% if self.student_choice == '2' %} checked{% endif %}></label>
</span>
<span class="choice">
<label><input type="radio" name="{{ self.name }}" value="3"{% if self.student_choice == '3' %} checked{% endif %}></label>
</span>
<span class="choice">
<label><input type="radio" name="{{ self.name }}" value="4"{% if self.student_choice == '4' %} checked{% endif %}></label>
</span>
<span class="choice">
<label><input type="radio" name="{{ self.name }}" value="5"{% if self.student_choice == '5' %} checked{% endif %}></label>
</span>
<span class="low">{{ self.high }}</span>
</div>
</fieldset>
<fieldset class="yes-no-unsure">
<legend>{{ self.question }}</legend>
<div class="choices">
<span class="choice">
<label><input type="radio" name="{{ self.name }}" value="yes"{% if self.student_choice == 'yes' %} checked{% endif %}> Yes</label>
</span>
<span class="choice">
<label><input type="radio" name="{{ self.name }}" value="no"{% if self.student_choice == 'yes' %} checked{% endif %}> No</label>
</span>
<span class="choice">
<label><input type="radio" name="{{ self.name }}" value="unsure"{% if self.student_choice == 'yes' %} checked{% endif %}> Unsure</label>
</span>
</div>
</fieldset>
...@@ -7,22 +7,22 @@ ...@@ -7,22 +7,22 @@
<answer name="improvement_goal" read_only="true" /> <answer name="improvement_goal" read_only="true" />
<quizz type="yes-no-unsure"> <quizz name="goal_true" type="yes-no-unsure">
<question>Is this goal true for you?</question> <question>Is this goal true for you?</question>
<tip>A goal that is true to you ___. Please enter a new goal that does meet these criteria.</tip> <tip>A goal that is true to you ___. Please enter a new goal that does meet these criteria.</tip>
</quizz> </quizz>
<quizz type="yes-no-unsure"> <quizz name="goal_implicate" type="yes-no-unsure">
<question>Does this goal implicate you?</question> <question>Does this goal implicate you?</question>
<tip>A goal that implicates you ____. Please enter a new goal that does meet these criteria.</tip> <tip>A goal that implicates you ____. Please enter a new goal that does meet these criteria.</tip>
</quizz> </quizz>
<quizz type="rating" low="Far" high="Nearly there"> <quizz name="goal_close" type="rating" low="Far" high="Nearly there">
<question>How close are you to reaching this goal?</question> <question>How close are you to reaching this goal?</question>
<tip reject="5" display="4">Please enter a goal which you are less close to reach</tip> <tip reject="5" display="4">Please enter a goal which you are less close to reach</tip>
</quizz> </quizz>
<quizz type="rating" low="Least" high="Most"> <quizz name="goal_important" type="rating" low="Least" high="Most">
<question>How important is it to you?</question> <question>How important is it to you?</question>
<tip>Please enter a goal which is important for you.</tip> <tip>Please enter a goal which is important for you.</tip>
</quizz> </quizz>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment