Commit 60fc3cdd by Xavier Antoviaque

Add a type of quizz which allows custom choices with long human-readable labels

parent bb6ee4ce
from .answer import AnswerBlock from .answer import AnswerBlock
from .dataexport import MentoringDataExportBlock from .dataexport import MentoringDataExportBlock
from .quizz import QuizzBlock, QuizzTipBlock from .quizz import QuizzBlock, QuizzChoiceBlock, QuizzTipBlock
from .mentoring import MentoringBlock from .mentoring import MentoringBlock
from .table import MentoringTableBlock, MentoringTableColumnBlock from .table import MentoringTableBlock, MentoringTableColumnBlock
...@@ -69,12 +69,13 @@ class QuizzBlock(XBlock): ...@@ -69,12 +69,13 @@ 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):
if self.type not in ('yes-maybenot-understand', 'rating-understand'): if self.type not in ('yes-maybenot-understand', 'rating-understand', 'choices'):
raise ValueError, u'Invalid value for QuizzBlock.type: `{}`'.format(self.type) raise ValueError, u'Invalid value for QuizzBlock.type: `{}`'.format(self.type)
template_path = 'templates/html/quizz_{}.html'.format(self.type) template_path = 'templates/html/quizz_{}.html'.format(self.type)
html = render_template(template_path, { html = render_template(template_path, {
'self': self, 'self': self,
'custom_choices': self.custom_choices,
}) })
fragment = Fragment(html) fragment = Fragment(html)
...@@ -83,6 +84,15 @@ class QuizzBlock(XBlock): ...@@ -83,6 +84,15 @@ class QuizzBlock(XBlock):
fragment.initialize_js('QuizzBlock') fragment.initialize_js('QuizzBlock')
return fragment return fragment
@property
def custom_choices(self):
custom_choices = []
for child_id in self.children: # pylint: disable=E1101
child = self.runtime.get_block(child_id)
if isinstance(child, QuizzChoiceBlock):
custom_choices.append(child)
return custom_choices
def submit(self, submission): def submit(self, submission):
log.debug(u'Received quizz submission: "%s"', submission) log.debug(u'Received quizz submission: "%s"', submission)
...@@ -98,6 +108,7 @@ class QuizzBlock(XBlock): ...@@ -98,6 +108,7 @@ class QuizzBlock(XBlock):
'self': self, 'self': self,
'tips': formatted_tips_list, 'tips': formatted_tips_list,
'submission': submission, 'submission': submission,
'submission_display': self.get_submission_display(submission),
}) })
else: else:
formatted_tips = u'' formatted_tips = u''
...@@ -111,6 +122,15 @@ class QuizzBlock(XBlock): ...@@ -111,6 +122,15 @@ class QuizzBlock(XBlock):
log.debug(u'Quizz submission result: %s', result) log.debug(u'Quizz submission result: %s', result)
return result return result
def get_submission_display(self, submission):
"""
Get the human-readable version of a submission value
"""
for choice in self.custom_choices:
if choice.value == submission:
return choice.content
return submission.upper()
def get_tips(self): def get_tips(self):
""" """
Returns the tips contained in this block Returns the tips contained in this block
...@@ -156,6 +176,10 @@ class QuizzTipBlock(XBlock): ...@@ -156,6 +176,10 @@ class QuizzTipBlock(XBlock):
return ['maybenot', 'understand'] return ['maybenot', 'understand']
elif quizz.type == 'rating-understand': elif quizz.type == 'rating-understand':
return ['1', '2', '3', 'understand'] return ['1', '2', '3', 'understand']
elif quizz.type == 'choice':
return []
else:
raise ValueError, 'Unknown quizz type, could not determine defaults'
else: else:
return reject return reject
...@@ -169,3 +193,10 @@ class QuizzTipBlock(XBlock): ...@@ -169,3 +193,10 @@ class QuizzTipBlock(XBlock):
if choice not in display] if choice not in display]
return display return display
class QuizzChoiceBlock(XBlock):
"""
Custom choice of an answer for a quizz
"""
value = String(help="Value of the choice when selected", scope=Scope.content, default="")
content = String(help="Human-readable version of the choice value", scope=Scope.content, default="")
...@@ -8,6 +8,7 @@ BLOCKS = [ ...@@ -8,6 +8,7 @@ BLOCKS = [
'answer = mentoring:AnswerBlock', 'answer = mentoring:AnswerBlock',
'quizz = mentoring:QuizzBlock', 'quizz = mentoring:QuizzBlock',
'tip = mentoring:QuizzTipBlock', 'tip = mentoring:QuizzTipBlock',
'choice = mentoring:QuizzChoiceBlock',
] ]
setup( setup(
......
<fieldset class="choices">
<legend>{{ self.question }}</legend>
<div class="choices">
{% for choice in custom_choices %}
<span class="choice">
<label><input type="radio" name="{{ self.name }}" value="{{ choice.value }}"{% if self.student_choice == '{{ choice.value }}' %} checked{% endif %}> {{ choice.content }}</label>
</span>
{% endfor %}
</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>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<strong> <strong>
To the question <em>"{{ self.question }}"</em>, To the question <em>"{{ self.question }}"</em>,
{% if submission %} {% if submission %}
you answered <em>"{{ submission }}"</em>. you answered <em>"{{ submission_display }}"</em>.
{% else %} {% else %}
you have not provided an answer. you have not provided an answer.
{% endif %} {% endif %}
......
...@@ -19,14 +19,20 @@ ...@@ -19,14 +19,20 @@
<tip reject="understand">Behaviors that work against achieving your goal are the things that you do that do not move your closer to your goal. Instead, they move you further away. For example, if my Improvement Goal is "to get better at listening to my employees," some behaviors that work against that might be: "I don't ask my employees to tell me what they think. I do all the talking. When employees do talk, I often interrupt them." All of those behaviors take me further away from my Improvement Goal.</tip> <tip reject="understand">Behaviors that work against achieving your goal are the things that you do that do not move your closer to your goal. Instead, they move you further away. For example, if my Improvement Goal is "to get better at listening to my employees," some behaviors that work against that might be: "I don't ask my employees to tell me what they think. I do all the talking. When employees do talk, I often interrupt them." All of those behaviors take me further away from my Improvement Goal.</tip>
</quizz> </quizz>
<quizz name="doing-not-doing-not-explain-why" type="yes-maybe-understand" labels="Yes, I don't explain why;Maybe I do explain a little;I don't understand"> <quizz name="doing-not-doing-not-explain-why" type="choices">
<question>Do you make sure not to explain why you are doing those things?</question> <question>Do you make sure not to explain why you are doing those things?</question>
<choice value="yes">Yes, I don't explain why</choice>
<choice value="maybe">Maybe I do explain a little</choice>
<choice value="understand">I don't understand</choice>
<tip reject="maybe">It may be tempting to include all the reasons why you are doing things that run counter to your column 1 Improvement Goal and to start identifying how you could start making changes to your behavior. But please don't include these reasons. Just make as long and juicy a list as you can of the things you do and don't do that undermine your column 1 goal. This probably won't feel so good, because you will feel like you are "telling on" yourself and admitting to all of the ways you are "naughty." But as you'll see, this list of behaviors will be a very valuable resource to you in helping you learn something new and important about yourself. If your list of "doing/not doing insteads" isn't a list of a handful of behaviors that undermine your column 1, go back and revise that list to make it meets the criteria. You can revise your work by TODO-LINK.</tip> <tip reject="maybe">It may be tempting to include all the reasons why you are doing things that run counter to your column 1 Improvement Goal and to start identifying how you could start making changes to your behavior. But please don't include these reasons. Just make as long and juicy a list as you can of the things you do and don't do that undermine your column 1 goal. This probably won't feel so good, because you will feel like you are "telling on" yourself and admitting to all of the ways you are "naughty." But as you'll see, this list of behaviors will be a very valuable resource to you in helping you learn something new and important about yourself. If your list of "doing/not doing insteads" isn't a list of a handful of behaviors that undermine your column 1, go back and revise that list to make it meets the criteria. You can revise your work by TODO-LINK.</tip>
<tip reject="understand">Explaining why you are doing these things means you are including the reasons for the things you do (or don't do) that undermine your column 1 Improvement Goal. For example, if my Improvement Goal is "to get better at taking care of myself," and I wrote in column 2 "I don't take enough time to relax at the end of the day," I should not include explanations about why I don't take enough time at the end of the day. We are sure you have good reasons! But don't include them here.</tip> <tip reject="understand">Explaining why you are doing these things means you are including the reasons for the things you do (or don't do) that undermine your column 1 Improvement Goal. For example, if my Improvement Goal is "to get better at taking care of myself," and I wrote in column 2 "I don't take enough time to relax at the end of the day," I should not include explanations about why I don't take enough time at the end of the day. We are sure you have good reasons! But don't include them here.</tip>
</quizz> </quizz>
<quizz name="doing-not-doing-not-explain-how" type="yes-maybe-understand" labels="Yes, I don't explain how I will change;Maybe I do explain a little;I don't understand"> <quizz name="doing-not-doing-not-explain-how" type="choices">
<question>Do you make sure not to explain how you will change?</question> <question>Do you make sure not to explain how you will change?</question>
<choice value="yes">Yes, I don't explain how I will change</choice>
<choice value="maybe">Maybe I do explain a little</choice>
<choice value="understand">I don't understand</choice>
<tip reject="maybe">You may want to start explaining what you now plan to do to eliminate, stop, or cut out these behaviors. But that means that you're trying to engage in improvement by assuming you can just cut out your bad behaviors or just start doing new, more productive things. You are taking what we call a New Year's Resolution approach to change, assuming that when you know that what you are doing is "naughty," you can will yourself to make those changes. As with New Year's Resolutions, we find that this approach does not often lead to success. Maybe you have had that experience too? Immunity to Change presents a different approach to change, so please put your attempts to start solving your problems on hold for a while longer. We're still getting a clear picture of the problem, and that is our focus for now. We think you'll find it worth the wait! If your list of "doing/not doing insteads" isn't a list of a handful of behaviors that undermine your column 1, go back and revise that list so that each entry meets the criteria. You can revise your work by TODO-LINK.</tip> <tip reject="maybe">You may want to start explaining what you now plan to do to eliminate, stop, or cut out these behaviors. But that means that you're trying to engage in improvement by assuming you can just cut out your bad behaviors or just start doing new, more productive things. You are taking what we call a New Year's Resolution approach to change, assuming that when you know that what you are doing is "naughty," you can will yourself to make those changes. As with New Year's Resolutions, we find that this approach does not often lead to success. Maybe you have had that experience too? Immunity to Change presents a different approach to change, so please put your attempts to start solving your problems on hold for a while longer. We're still getting a clear picture of the problem, and that is our focus for now. We think you'll find it worth the wait! If your list of "doing/not doing insteads" isn't a list of a handful of behaviors that undermine your column 1, go back and revise that list so that each entry meets the criteria. You can revise your work by TODO-LINK.</tip>
<tip reject="understand">If you are explaining how you will change, you are coming up with ideas and plans for how to stop doing these "bad" behaviors. You are seeing that you are working against your goal, and you probably want to stop doing that! But, we find that simply trying to change bad behaviors does not often lead to success for many people. Maybe you have had that experience too? Immunity to Change presents a different approach to change, so please put don't start trying to solve your problems yet. We're still getting a clear picture of the problem, and that is our focus for now. We think you'll find it worth the wait!</tip> <tip reject="understand">If you are explaining how you will change, you are coming up with ideas and plans for how to stop doing these "bad" behaviors. You are seeing that you are working against your goal, and you probably want to stop doing that! But, we find that simply trying to change bad behaviors does not often lead to success for many people. Maybe you have had that experience too? Immunity to Change presents a different approach to change, so please put don't start trying to solve your problems yet. We're still getting a clear picture of the problem, and that is our focus for now. We think you'll find it worth the wait!</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