Commit 03062df9 by Douglas Cerna

Initial implementation

parent 27e2f4ba
......@@ -167,6 +167,42 @@ class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock):
self._(u"A choice value listed as correct does not exist: {choice}").format(choice=choice_name(val))
)
def student_view_data(self):
"""
Returns a JSON representation of the student_view of this XBlock,
retrievable from the Course Block API.
"""
return {
'id': self.url_name,
'type': self.CATEGORY,
'question': self.question,
'message': self.message,
'choices': [
{'value': choice['value'], 'content': choice['display_name']}
for choice in self.human_readable_choices
],
'weight': self.weight,
'correct_choices': self.correct_choices,
'tips': [
{'content': tip.content, 'for_choices': tip.values}
for tip in self.get_tips()
],
'user_state': {
'student_choice': self.student_choice,
},
}
@property
def url_name(self):
"""
Get the url_name for this block. In Studio/LMS it is provided by a mixin, so we just
defer to super(). In the workbench or any other platform, we use the usage_id.
"""
try:
return super(MCQBlock, self).url_name
except AttributeError:
return unicode(self.scope_ids.usage_id)
class RatingBlock(MCQBlock):
"""
......
......@@ -905,6 +905,38 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerWithNestedXBlocksMixin,
"""
return loader.load_scenarios_from_path('templates/xml')
def student_view_data(self):
"""
Returns a JSON representation of the student_view of this XBlock,
retrievable from the Course Block API.
"""
components = []
for child_id in self.children:
block = self.runtime.get_block(child_id)
if hasattr(block, 'student_view_data'):
components.append(block.student_view_data())
return {
'max_attempts': self.max_attempts,
'user_state': {
'num_attempts': self.num_attempts,
'attempted': self.attempted,
'completed': self.completed,
'student_results': self.student_results,
'step': self.step,
},
'extended_feedback': self.extended_feedback,
'feedback_label': self.feedback_label,
'components': components,
'messages': {
message_type: get_message_label(message_type)
for message_type in (
'completed',
'incomplete',
'max_attempts_reached',
)
}
}
class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNestedXBlocksMixin):
"""
......
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