Commit 925a31ef by Xavier Antoviaque

Adds support for QuizzBlock.reject and .display properties

parent 7cf1bb93
...@@ -24,9 +24,9 @@ def commas_to_list(commas_str): ...@@ -24,9 +24,9 @@ def commas_to_list(commas_str):
Converts a comma-separated string to a list Converts a comma-separated string to a list
""" """
if commas_str is None: if commas_str is None:
return None return None # Means default value (which can be non-empty)
elif commas_str == '': elif commas_str == '':
return [] return [] # Means empty list
else: else:
return commas_str.split(',') return commas_str.split(',')
...@@ -42,7 +42,7 @@ class QuizzBlock(XBlock): ...@@ -42,7 +42,7 @@ class QuizzBlock(XBlock):
low = String(help="Label for low ratings", scope=Scope.content, default="Less") low = String(help="Label for low ratings", scope=Scope.content, default="Less")
high = String(help="Label for high ratings", scope=Scope.content, default="More") 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 choices to display the tip for", scope=Scope.content, default=None) display = List(help="List of choices to display the tip for", scope=Scope.content, default=None)
reject = List(help="List of choices to reject", scope=Scope.content, default=None) reject = List(help="List of choices to reject", scope=Scope.content, default=None)
student_choice = String(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)
...@@ -88,9 +88,9 @@ class QuizzBlock(XBlock): ...@@ -88,9 +88,9 @@ class QuizzBlock(XBlock):
def submit(self, submission): def submit(self, submission):
log.info(u'Received quizz submission: %s', submission) log.info(u'Received quizz submission: %s', submission)
# TODO completed = self.is_completed(submission)
completed = bool(submission) show_tip = self.is_tip_shown(submission)
show_tip = completed self.student_choice = submission
if show_tip: if show_tip:
formatted_tip = render_template('static/html/tip.html', { formatted_tip = render_template('static/html/tip.html', {
...@@ -105,7 +105,25 @@ class QuizzBlock(XBlock): ...@@ -105,7 +105,25 @@ class QuizzBlock(XBlock):
'tip': formatted_tip, 'tip': formatted_tip,
} }
#self.student_input = submission[0]['value'] def is_completed(self, submission):
#log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input)) return submission and submission not in self.reject_with_defaults
#return self.student_choice
def is_tip_shown(self, submission):
return not submission or submission in self.display_with_defaults
@property
def reject_with_defaults(self):
if self.reject is None:
if self.type == 'yes-no-unsure':
return ['no', 'unsure']
elif self.type == 'rating':
return [1, 2, 3]
else:
return self.reject
@property
def display_with_defaults(self):
if self.display is None:
return self.reject_with_defaults
else:
return self.display
<div class="quizz-tip"> <div class="quizz-tip">
<h3>{{ self.question }}</h2> <strong>
To the question <em>"{{ self.question }}"</em>,
{% if self.student_choice %}
you answered <em>"{{ self.student_choice }}"</em>.
{% else %}
you have not provided an answer.
{% endif %}
</strong>
<p>{{ self.tip }}</p> <p>{{ self.tip }}</p>
</div> </div>
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