Commit 79bdff76 by Tim Krones Committed by Tim Krones

Introduce instance-wide setting that specifies if previous answers to

MCQs are shown when users revisit them.
parent 5e5d897c
......@@ -63,6 +63,10 @@ _default_theme_config = {
'locations': ['public/themes/lms.css']
}
_default_options_config = {
'pb_mcq_hide_previous_answer': False
}
# Make '_' a no-op so we can scrape strings
def _(text):
......@@ -121,6 +125,7 @@ class BaseMentoringBlock(
icon_class = 'problem'
block_settings_key = 'mentoring'
theme_key = 'theme'
options_key = 'options'
@property
def url_name(self):
......@@ -156,18 +161,28 @@ class BaseMentoringBlock(
return [self.display_name]
return []
def get_theme(self):
def get_settings(self, settings_key, default):
"""
Gets theme settings from settings service. Falls back to default (LMS) theme
if settings service is not available, xblock theme settings are not set or does
contain mentoring theme settings.
Get settings identified by `settings_key` from settings service.
Fall back on `default` if settings service is unavailable
or settings have not been customized.
"""
settings_service = self.runtime.service(self, "settings")
if settings_service:
xblock_settings = settings_service.get_settings_bucket(self)
if xblock_settings and self.theme_key in xblock_settings:
return xblock_settings[self.theme_key]
return _default_theme_config
if xblock_settings and settings_key in xblock_settings:
return xblock_settings[settings_key]
return default
def get_theme(self):
"""
Get theme settings for this block from settings service.
Fall back on default (LMS) theme if settings service is not available,
or theme has not been customized.
"""
return self.get_settings(self.theme_key, _default_theme_config)
def include_theme_files(self, fragment):
theme = self.get_theme()
......@@ -175,6 +190,18 @@ class BaseMentoringBlock(
for theme_file in theme_files:
fragment.add_css(ResourceLoader(theme_package).load_unicode(theme_file))
def get_options(self):
"""
Get options settings for this block from settings service.
Fall back on default options if settings service is not available
or options have not been customized.
"""
return self.get_settings(self.options_key, _default_options_config)
def get_option(self, option):
return self.get_options()[option]
@XBlock.json_handler
def view(self, data, suffix=''):
"""
......@@ -368,6 +395,8 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM
return Score(score, int(round(score * 100)), correct, incorrect, partially_correct)
def student_view(self, context):
from .mcq import MCQBlock # Import here to avoid circular dependency
# Migrate stored data if necessary
self.migrate_fields()
......@@ -379,6 +408,8 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM
fragment = Fragment()
child_content = u""
mcq_hide_previous_answer = self.get_option('pb_mcq_hide_previous_answer')
for child_id in self.children:
child = self.runtime.get_block(child_id)
if child is None: # child should not be None but it can happen due to bugs or permission issues
......@@ -388,6 +419,10 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM
if self.is_assessment and isinstance(child, QuestionMixin):
child_fragment = child.render('assessment_step_view', context)
else:
if mcq_hide_previous_answer and isinstance(child, MCQBlock):
context['hide_prev_answer'] = True
else:
context['hide_prev_answer'] = False
child_fragment = child.render('mentoring_view', context)
except NoSuchViewError:
if child.scope_ids.block_type == 'html' and getattr(self.runtime, 'is_author_mode', False):
......
......@@ -138,6 +138,8 @@ function MCQBlock(runtime, element) {
var choiceResultDOM = $('.choice-result', choiceDOM);
var choiceTipsDOM = $('.choice-tips', choiceDOM);
if (choiceInputDOM.prop('checked')) { // We're showing previous answers,
// so go ahead and display results as well
if (result.status === "correct" && choiceInputDOM.val() === result.submission) {
choiceDOM.addClass('correct');
choiceResultDOM.addClass('checkmark-correct icon-ok fa-check');
......@@ -156,6 +158,7 @@ function MCQBlock(runtime, element) {
messageView.showMessage(choiceTipsDOM);
}
});
}
});
if (_.isNull(result.submission)) {
......
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