Commit 31c89e6d by Diana Huang

Consolidate error messages.

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