From a28b4ce18e4c9d87fd8af05eb2fe8fada5f6e4ee Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Thu, 1 Nov 2012 13:32:05 -0400 Subject: [PATCH] added extensions to persist state --- .../js/src/selfassessment/display.coffee | 2 -- .../xmodule/xmodule/self_assessment_module.py | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee b/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee index add21ee927..b6aaf90bdb 100644 --- a/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee @@ -1,5 +1,4 @@ $(document).on('click', 'section.sa-wrapper input#show', ( -> - root = location.protocol + "//" + location.host post_url=$('section.sa-wrapper input#show').attr('url') final_url="/courses/MITx/6.002x/2012_Fall/modx/#{post_url}/sa_show" answer=$('section.sa-wrapper textarea#answer').val() @@ -13,7 +12,6 @@ $(document).on('click', 'section.sa-wrapper input#show', ( -> $(document).on('click', 'section.sa-wrapper input#save', ( -> assessment_correct=$('section.sa-wrapper #assessment').find(':selected').text() - root = location.protocol + "//" + location.host post_url=$('section.sa-wrapper input#save').attr('url') final_url="/courses/MITx/6.002x/2012_Fall/modx/#{post_url}/sa_save" $.post final_url, assessment_correct, (response) -> diff --git a/common/lib/xmodule/xmodule/self_assessment_module.py b/common/lib/xmodule/xmodule/self_assessment_module.py index cd443a9de2..438f2601e6 100644 --- a/common/lib/xmodule/xmodule/self_assessment_module.py +++ b/common/lib/xmodule/xmodule/self_assessment_module.py @@ -82,22 +82,34 @@ class SelfAssessmentModule(XModule): self.score=0 self.top_score=1 self.submit_message=etree.tostring(dom2.xpath('submitmessage')[0]) - log.debug(self.submit_message) self.attempts = 0 - self.max_attempts = 1 self.max_attempts = self.metadata.get('attempts', None) if self.max_attempts is not None: self.max_attempts = int(self.max_attempts) else: self.max_attempts=1 + self.correctness="incorrect" + self.done=False if instance_state is not None: instance_state = json.loads(instance_state) + log.debug(instance_state) + if instance_state is not None and 'attempts' in instance_state: self.attempts = instance_state['attempts'] - self.correctness="incorrect" + if instance_state is not None and 'student_answers' in instance_state: + self.answer=instance_state['student_answers'] + + if instance_state is not None and 'done' in instance_state: + self.done=instance_state['done'] + + if instance_state is not None and 'correct_map' in instance_state: + if 'self_assess' in instance_state['correct_map']: + self.score=instance_state['correct_map']['self_assess']['npoints'] + self.correctness=instance_state['correct_map']['self_assess']['correctness'] + def get_score(self): @@ -166,6 +178,7 @@ class SelfAssessmentModule(XModule): if self.correctness=="correct" : points=1 event_info = dict() + self.done=True event_info['state'] = {'seed': 1, 'student_answers': self.answer, 'correct_map': {'self_assess' : {'correctness': self.correctness, @@ -181,6 +194,8 @@ class SelfAssessmentModule(XModule): event_info['answers'] = self.answer + self.attempts = self.attempts + 1 + self.system.track_function('save_problem_succeed', event_info) return {'success': True, 'message' : self.submit_message} @@ -189,7 +204,7 @@ class SelfAssessmentModule(XModule): points=0 if self.correctness=="correct" : points=1 - state= return {'seed': 1, + state= {'seed': 1, 'student_answers': self.answer, 'correct_map': {'self_assess' : {'correctness': self.correctness, 'npoints': points,