Commit d5ea6f63 by Braden MacDonald

Address Cale's review comments

parent cda7fd0d
......@@ -168,7 +168,8 @@ class AnswerBlock(AnswerMixin, StepMixin, StudioEditableXBlockMixin, XBlock):
return student_input
def fallback_view(self, view_name, context=None):
def mentoring_view(self, context=None):
""" Render this XBlock within a mentoring block. """
context = context or {}
context['self'] = self
html = loader.render_template('templates/html/answer_editable.html', context)
......@@ -179,7 +180,15 @@ class AnswerBlock(AnswerMixin, StepMixin, StudioEditableXBlockMixin, XBlock):
fragment.initialize_js('AnswerBlock')
return fragment
def student_view(self, context=None):
""" Normal view of this XBlock, identical to mentoring_view """
return self.mentoring_view(context)
def submit(self, submission):
"""
The parent block is handling a student submission, including a new answer for this
block. Update accordingly.
"""
self.student_input = submission[0]['value'].strip()
self.save()
log.info(u'Answer submitted for`{}`: "{}"'.format(self.name, self.student_input))
......@@ -260,7 +269,8 @@ class AnswerRecapBlock(AnswerMixin, StudioEditableXBlockMixin, XBlock):
return self.get_model_object().student_input
return ''
def fallback_view(self, view_name, context=None):
def mentoring_view(self, context=None):
""" Render this XBlock within a mentoring block. """
context = context or {}
context['title'] = self.display_name
context['description'] = self.description
......@@ -270,3 +280,7 @@ class AnswerRecapBlock(AnswerMixin, StudioEditableXBlockMixin, XBlock):
fragment = Fragment(html)
fragment.add_css_url(self.runtime.local_resource_url(self, 'public/css/answer.css'))
return fragment
def student_view(self, context=None):
""" Normal view of this XBlock, identical to mentoring_view """
return self.mentoring_view(context)
......@@ -68,9 +68,14 @@ class ChoiceBlock(StudioEditableXBlockMixin, XBlock):
status = self._(u"Out of Context") # Parent block should implement describe_choice_correctness()
return self._(u"Choice ({status})").format(status=status)
def fallback_view(self, view_name, context):
def mentoring_view(self, context=None):
""" Render this choice string within a mentoring block question. """
return Fragment(u'<span class="choice-text">{}</span>'.format(self.content))
def student_view(self, context=None):
""" Normal view of this XBlock, identical to mentoring_view """
return self.mentoring_view(context)
def validate_field_data(self, validation, data):
"""
Validate this block's field data.
......
......@@ -83,7 +83,7 @@ class MCQBlock(QuestionnaireAbstractBlock):
tips_html.append(tip.render('mentoring_view').content)
if tips_html:
formatted_tips = ResourceLoader(__name__).render_template('templates/html/tip_choice_group.html', {
formatted_tips = loader.render_template('templates/html/tip_choice_group.html', {
'tips_html': tips_html,
})
......
......@@ -341,7 +341,7 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC
self.attempted = True
if self.is_assessment:
return self.handleAssessmentSubmit(submissions, suffix)
return self.handle_assessment_submit(submissions, suffix)
submit_results = []
completed = True
......@@ -410,8 +410,7 @@ class MentoringBlock(XBlock, StepParentMixin, StudioEditableXBlockMixin, StudioC
'num_attempts': self.num_attempts
}
def handleAssessmentSubmit(self, submissions, suffix):
def handle_assessment_submit(self, submissions, suffix):
completed = False
current_child = None
children = [self.runtime.get_block(child_id) for child_id in self.children]
......
......@@ -64,10 +64,15 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin):
""" translate text """
return self.runtime.service(self, "i18n").ugettext(text)
def fallback_view(self, view_name, context):
def mentoring_view(self, context=None):
""" Render this message for use by a mentoring block. """
html = u'<div class="message {msg_type}">{content}</div>'.format(msg_type=self.type, content=self.content)
return Fragment(html)
def student_view(self, context=None):
""" Normal view of this XBlock, identical to mentoring_view """
return self.mentoring_view(context)
@property
def display_name_with_default(self):
if self.type == 'max_attempts_reached':
......
......@@ -142,15 +142,6 @@ class QuestionnaireAbstractBlock(StudioEditableXBlockMixin, StudioContainerXBloc
def mentoring_view(self, context=None):
return self.student_view(context)
def assessment_step_view(self, context=None):
"""
assessment_step_view is the same as mentoring_view, except its DIV will have a different
class (.xblock-v1-assessment_step_view) that we use for assessments to hide all the
steps with CSS and to detect which children of mentoring are "Steps" and which are just
decorative elements/instructions.
"""
return self.mentoring_view(context)
@property
def custom_choices(self):
custom_choices = []
......
......@@ -66,15 +66,18 @@ class StepMixin(object):
def author_view(self, context):
context = context or {}
context['hide_header'] = True
try:
return self.mentoring_view(context)
except AttributeError:
return self.fallback_view('mentoring_view', context)
return self.mentoring_view(context)
def author_preview_view(self, context):
context = context or {}
context['hide_header'] = True
try:
return self.student_view(context)
except AttributeError:
return self.fallback_view('student_view', context)
return self.student_view(context)
def assessment_step_view(self, context=None):
"""
assessment_step_view is the same as mentoring_view, except its DIV will have a different
class (.xblock-v1-assessment_step_view) that we use for assessments to hide all the
steps with CSS and to detect which children of mentoring are "Steps" and which are just
decorative elements/instructions.
"""
return self.mentoring_view(context)
......@@ -134,7 +134,8 @@ class MentoringTableColumn(StudioEditableXBlockMixin, StudioContainerXBlockMixin
editable_fields = ("header", )
has_children = True
def fallback_view(self, view_name, context):
def mentoring_view(self, context=None):
""" Render this XBlock within a mentoring block. """
context = context or {}
fragment = Fragment()
for child_id in self.children:
......@@ -144,13 +145,17 @@ class MentoringTableColumn(StudioEditableXBlockMixin, StudioContainerXBlockMixin
# with HTML we don't want. So just grab its HTML directly.
child_frag = Fragment(child.data)
else:
child_frag = child.render(view_name, context)
child_frag = child.render('mentoring_view', context)
fragment.add_content(child_frag.content)
fragment.add_frag_resources(child_frag)
return fragment
def author_preview_view(self, context):
return self.fallback_view('mentoring_view', context)
return self.mentoring_view(context)
def student_view(self, context=None):
""" Normal view of this XBlock, identical to mentoring_view """
return self.mentoring_view(context)
def author_edit_view(self, context):
"""
......
......@@ -30,6 +30,8 @@ from xblock.validation import ValidationMessage
from xblockutils.resources import ResourceLoader
from xblockutils.studio_editable import StudioEditableXBlockMixin
loader = ResourceLoader(__name__)
# Make '_' a no-op so we can scrape strings
def _(text):
......@@ -86,14 +88,19 @@ class TipBlock(StudioEditableXBlockMixin, XBlock):
values_list.append(display_name)
return self._(u"Tip for {list_of_choices}").format(list_of_choices=u", ".join(values_list))
def fallback_view(self, view_name, context):
html = ResourceLoader(__name__).render_template("templates/html/tip.html", {
def mentoring_view(self, context=None):
""" Render this XBlock within a mentoring block. """
html = loader.render_template("templates/html/tip.html", {
'content': self.content,
'width': self.width,
'height': self.height,
})
return Fragment(html)
def student_view(self, context=None):
""" Normal view of this XBlock, identical to mentoring_view """
return self.mentoring_view(context)
def clean_studio_edits(self, data):
"""
Clean up the edits during studio_view save
......
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