Commit 24689024 by Vik Paruchuri

Refactor open ended module

parent 5333e5e1
......@@ -411,7 +411,6 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
<other request-specific values here > }
'''
handlers = {
'problem_get': self.get_problem,
'save_answer': self.save_answer,
'score_update': self.update_score,
'save_post_assessment' : self.message_post,
......@@ -429,23 +428,6 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
})
return json.dumps(d, cls=ComplexEncoder)
def get_problem(self, get, system):
return self.get_html(system)
def reset_problem(self, get, system):
self.change_state(self.INITIAL)
return {'success': True}
def out_of_sync_error(self, get, msg=''):
"""
return dict out-of-sync error message, and also log.
"""
log.warning("Assessment module state out sync. state: %r, get: %r. %s",
self.state, get, msg)
return {'success': False,
'error': 'The problem state got out-of-sync'}
def save_answer(self, get, system):
if self.attempts > self.max_attempts:
# If too many attempts, prevent student from saving answer and
......@@ -483,19 +465,6 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
return dict() # No AJAX return is needed
def change_state(self, new_state):
"""
A centralized place for state changes--allows for hooks. If the
current state matches the old state, don't run any hooks.
"""
if self.state == new_state:
return
self.state = new_state
if self.state == self.DONE:
self.attempts += 1
def get_html(self, system):
#set context variables and render template
if self.state != self.INITIAL:
......@@ -525,29 +494,6 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
html = system.render_template('open_ended.html', context)
return html
def get_progress(self):
'''
For now, just return last score / max_score
'''
if self._max_score > 0:
try:
return Progress(self.get_score()['score'], self._max_score)
except Exception as err:
log.exception("Got bad progress")
return None
return None
def reset(self, system):
"""
If resetting is allowed, reset the state.
Returns {'success': bool, 'error': msg}
(error only present if not success)
"""
self.change_state(self.INITIAL)
return {'success': True}
class OpenEndedDescriptor(XmlDescriptor, EditingDescriptor):
"""
Module for adding self assessment questions to courses
......
......@@ -206,5 +206,43 @@ class OpenEndedChild():
return {'score': score if score is not None else 0,
'total': self._max_score}
def reset(self, system):
"""
If resetting is allowed, reset the state.
Returns {'success': bool, 'error': msg}
(error only present if not success)
"""
self.change_state(self.INITIAL)
return {'success': True}
def get_progress(self):
'''
For now, just return last score / max_score
'''
if self._max_score > 0:
try:
return Progress(self.get_score()['score'], self._max_score)
except Exception as err:
log.exception("Got bad progress")
return None
return None
def out_of_sync_error(self, get, msg=''):
"""
return dict out-of-sync error message, and also log.
"""
log.warning("Assessment module state out sync. state: %r, get: %r. %s",
self.state, get, msg)
return {'success': False,
'error': 'The problem state got out-of-sync'}
def get_html(self):
pass
def handle_ajax(self):
pass
......@@ -116,18 +116,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
html = system.render_template('self_assessment_prompt.html', context)
return html
def get_progress(self):
'''
For now, just return last score / max_score
'''
if self._max_score > 0:
try:
return Progress(self.get_score()['score'], self._max_score)
except Exception as err:
log.exception("Got bad progress")
return None
return None
def handle_ajax(self, dispatch, get, system):
"""
......@@ -158,15 +146,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
})
return json.dumps(d, cls=ComplexEncoder)
def out_of_sync_error(self, get, msg=''):
"""
return dict out-of-sync error message, and also log.
"""
log.warning("Assessment module state out sync. state: %r, get: %r. %s",
self.state, get, msg)
return {'success': False,
'error': 'The problem state got out-of-sync'}
def get_rubric_html(self,system):
"""
Return the appropriate version of the rubric, based on the state.
......@@ -296,7 +275,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
d['state'] = self.state
return d
def save_hint(self, get, system):
'''
Save the hint.
......@@ -320,25 +298,6 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
'allow_reset': self._allow_reset()}
def reset(self, system):
"""
If resetting is allowed, reset the state.
Returns {'success': bool, 'error': msg}
(error only present if not success)
"""
#if self.state != self.DONE:
# return self.out_of_sync_error(get)
#if self.attempts > self.max_attempts:
# return {
# 'success': False,
# 'error': 'Too many attempts.'
# }
self.change_state(self.INITIAL)
return {'success': True}
class SelfAssessmentDescriptor(XmlDescriptor, EditingDescriptor):
"""
......
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