Commit 7eb4970f by Victor Shnayder

Merge pull request #1671 from MITx/fix/will/save_button_regression

Fix/will/save button regression
parents 4b5837ff ce5e8689
...@@ -310,11 +310,26 @@ class CapaModule(XModule): ...@@ -310,11 +310,26 @@ class CapaModule(XModule):
is_survey_question = (self.max_attempts == 0) is_survey_question = (self.max_attempts == 0)
needs_reset = self.is_completed() and self.rerandomize == "always" needs_reset = self.is_completed() and self.rerandomize == "always"
# If the student has unlimited attempts, and their answers
# are not randomized, then we do not need a save button
# because they can use the "Check" button without consequences.
#
# The consequences we want to avoid are:
# * Using up an attempt (if max_attempts is set)
# * Changing the current problem, and no longer being
# able to view it (if rerandomize is "always")
#
# In those cases. the if statement below is false,
# and the save button can still be displayed.
#
if self.max_attempts is None and self.rerandomize != "always":
return False
# If the problem is closed (and not a survey question with max_attempts==0), # If the problem is closed (and not a survey question with max_attempts==0),
# then do NOT show the reset button # then do NOT show the save button
# If we're waiting for the user to reset a randomized problem # If we're waiting for the user to reset a randomized problem
# then do NOT show the reset button # then do NOT show the save button
if (self.closed() and not is_survey_question) or needs_reset: elif (self.closed() and not is_survey_question) or needs_reset:
return False return False
else: else:
return True return True
...@@ -403,7 +418,7 @@ class CapaModule(XModule): ...@@ -403,7 +418,7 @@ class CapaModule(XModule):
# if we want to show a check button, and False otherwise # if we want to show a check button, and False otherwise
# This works because non-empty strings evaluate to True # This works because non-empty strings evaluate to True
if self.should_show_check_button(): if self.should_show_check_button():
check_button = self.check_button_name() check_button = self.check_button_name()
else: else:
check_button = False check_button = False
...@@ -556,7 +571,7 @@ class CapaModule(XModule): ...@@ -556,7 +571,7 @@ class CapaModule(XModule):
else: else:
answers = self.lcp.get_question_answers() answers = self.lcp.get_question_answers()
# answers (eg <solution>) may have embedded images # answers (eg <solution>) may have embedded images
# but be careful, some problems are using non-string answer dicts # but be careful, some problems are using non-string answer dicts
new_answers = dict() new_answers = dict()
for answer_id in answers: for answer_id in answers:
...@@ -606,7 +621,7 @@ class CapaModule(XModule): ...@@ -606,7 +621,7 @@ class CapaModule(XModule):
to 'input_1' in the returned dict) to 'input_1' in the returned dict)
''' '''
answers = dict() answers = dict()
for key in get: for key in get:
# e.g. input_resistor_1 ==> resistor_1 # e.g. input_resistor_1 ==> resistor_1
_, _, name = key.partition('_') _, _, name = key.partition('_')
...@@ -729,7 +744,7 @@ class CapaModule(XModule): ...@@ -729,7 +744,7 @@ class CapaModule(XModule):
event_info['answers'] = answers event_info['answers'] = answers
# Too late. Cannot submit # Too late. Cannot submit
if self.closed() and not self.max_attempts==0: if self.closed() and not self.max_attempts ==0:
event_info['failure'] = 'closed' event_info['failure'] = 'closed'
self.system.track_function('save_problem_fail', event_info) self.system.track_function('save_problem_fail', event_info)
return {'success': False, return {'success': False,
...@@ -747,7 +762,7 @@ class CapaModule(XModule): ...@@ -747,7 +762,7 @@ class CapaModule(XModule):
self.system.track_function('save_problem_success', event_info) self.system.track_function('save_problem_success', event_info)
msg = "Your answers have been saved" msg = "Your answers have been saved"
if not self.max_attempts==0: if not self.max_attempts ==0:
msg += " but not graded. Hit 'Check' to grade them." msg += " but not graded. Hit 'Check' to grade them."
return {'success': True, return {'success': True,
'msg': msg} 'msg': msg}
...@@ -784,7 +799,7 @@ class CapaModule(XModule): ...@@ -784,7 +799,7 @@ class CapaModule(XModule):
# reset random number generator seed (note the self.lcp.get_state() # reset random number generator seed (note the self.lcp.get_state()
# in next line) # in next line)
self.lcp.seed = None self.lcp.seed = None
self.lcp = LoncapaProblem(self.definition['data'], self.lcp = LoncapaProblem(self.definition['data'],
self.location.html_id(), self.lcp.get_state(), self.location.html_id(), self.lcp.get_state(),
...@@ -793,7 +808,7 @@ class CapaModule(XModule): ...@@ -793,7 +808,7 @@ class CapaModule(XModule):
event_info['new_state'] = self.lcp.get_state() event_info['new_state'] = self.lcp.get_state()
self.system.track_function('reset_problem', event_info) self.system.track_function('reset_problem', event_info)
return { 'success': True, return {'success': True,
'html': self.get_problem_html(encapsulate=False)} 'html': self.get_problem_html(encapsulate=False)}
...@@ -821,13 +836,13 @@ class CapaDescriptor(RawDescriptor): ...@@ -821,13 +836,13 @@ class CapaDescriptor(RawDescriptor):
def get_context(self): def get_context(self):
_context = RawDescriptor.get_context(self) _context = RawDescriptor.get_context(self)
_context.update({'markdown': self.metadata.get('markdown', ''), _context.update({'markdown': self.metadata.get('markdown', ''),
'enable_markdown' : 'markdown' in self.metadata}) 'enable_markdown': 'markdown' in self.metadata})
return _context return _context
@property @property
def editable_metadata_fields(self): def editable_metadata_fields(self):
"""Remove any metadata from the editable fields which have their own editor or shouldn't be edited by user.""" """Remove any metadata from the editable fields which have their own editor or shouldn't be edited by user."""
subset = [field for field in super(CapaDescriptor,self).editable_metadata_fields subset = [field for field in super(CapaDescriptor, self).editable_metadata_fields
if field not in ['markdown', 'empty']] if field not in ['markdown', 'empty']]
return subset return subset
......
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