Commit 31c89e6d by Diana Huang

Consolidate error messages.

parent c70531ae
...@@ -550,11 +550,9 @@ class OpenEndedModule(openendedchild.OpenEndedChild): ...@@ -550,11 +550,9 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
""" """
# Once we close the problem, we should not allow students # Once we close the problem, we should not allow students
# to save answers # to save answers
if self.closed(): closed, msg = self.check_if_closed()
return { if closed:
'success': False, return msg
'error': 'Problem is closed.'
}
if self.state != self.INITIAL: if self.state != self.INITIAL:
return self.out_of_sync_error(get) return self.out_of_sync_error(get)
......
...@@ -122,6 +122,22 @@ class OpenEndedChild(object): ...@@ -122,6 +122,22 @@ class OpenEndedChild(object):
return True return True
return False return False
def check_if_closed(self):
if self.closed():
return True, {
'success': False,
'error': 'This problem is now closed.'
}
elif self.attempts > self.max_attempts:
return True, {
'success': False,
'error': 'Too many attempts.'
}
else:
return False, {}
def latest_answer(self): def latest_answer(self):
"""Empty string if not available""" """Empty string if not available"""
if not self.history: if not self.history:
......
...@@ -190,11 +190,9 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild): ...@@ -190,11 +190,9 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
or 'rubric_html' (if success). or 'rubric_html' (if success).
""" """
# Check to see if this problem is closed # Check to see if this problem is closed
if self.closed(): closed, msg = self.check_if_closed()
return { if closed:
'success': False, return msg
'error': 'This problem is now closed.'
}
if self.state != self.INITIAL: if self.state != self.INITIAL:
return self.out_of_sync_error(get) return self.out_of_sync_error(get)
......
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