From 5b6045b5fceb14d39d2b1fef6a917bde3a6b0b75 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Thu, 1 Nov 2012 11:47:28 -0400 Subject: [PATCH] fixed ajax value passing to function --- .../js/src/selfassessment/display.coffee | 13 +------ .../xmodule/xmodule/self_assessment_module.py | 38 ++++--------------- 2 files changed, 8 insertions(+), 43 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee b/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee index f393fc79ec..5627325433 100644 --- a/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee @@ -9,23 +9,12 @@ $(document).on('click', 'section.sa-wrapper input#show', ( -> )); $(document).on('click', 'section.sa-wrapper input#save', ( -> - answer=$('section.sa-wrapper input#answer').val() - assessment=0 assessment_correct=$('section.sa-wrapper #assessment').find(':selected').text() - alert(assessment_correct) - 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_save" - $('section.sa-wrapper input#assessment option').each( -> - if (this.selected) - alert('this option is selected') - else - alert('this is not') - ); - - $.post final_url, answer, (response) -> + $.post final_url, assessment_correct, (response) -> if response.success $('section.sa_wrapper p#save_message').replace(response.message) diff --git a/common/lib/xmodule/xmodule/self_assessment_module.py b/common/lib/xmodule/xmodule/self_assessment_module.py index 3e65b16670..22c5b9c9f3 100644 --- a/common/lib/xmodule/xmodule/self_assessment_module.py +++ b/common/lib/xmodule/xmodule/self_assessment_module.py @@ -72,7 +72,7 @@ class SelfAssessmentModule(XModule): self.problem=''.join([self.problem,problem_form]) self.rubric=''.join([self.rubric,rubric_form]) self.html = self.problem - self.answers={} + self.answer="" self.score=0 self.top_score=1 @@ -124,22 +124,23 @@ class SelfAssessmentModule(XModule): }) return json.dumps(d, cls=ComplexEncoder) - - def show_rubric(self,get): + self.answer=get.keys()[0] return {'success': True, 'rubric' : self.rubric} - def save_problem(self, get): ''' Save the passed in answers. Returns a dict { 'success' : bool, ['error' : error-msg]}, with the error key only present if success is False. ''' + + correctness=get.keys()[0] + log.debug(correctness) event_info = dict() event_info['state'] = {'seed': 1, 'student_answers': self.answers, - 'correct_map': {'self_assess' : {'correctness': False, + 'correct_map': {'self_assess' : {'correctness': correctness, 'npoints': 0, 'msg': "", 'hint': "", @@ -150,37 +151,12 @@ class SelfAssessmentModule(XModule): event_info['problem_id'] = self.location.url() - answers = self.make_dict_of_responses(get) - log.debug(answers) - event_info['answers'] = answers + event_info['answers'] = self.answer self.system.track_function('save_problem_succeed', event_info) return {'success': True, 'message' : "Save Succcesful. Thanks for participating!"} - @staticmethod - def make_dict_of_responses(get): - '''Make dictionary of student responses (aka "answers") - get is POST dictionary. - ''' - answers = dict() - for key in get: - # e.g. input_resistor_1 ==> resistor_1 - _, _, name = key.partition('_') - - # This allows for answers which require more than one value for - # the same form input (e.g. checkbox inputs). The convention is that - # if the name ends with '[]' (which looks like an array), then the - # answer will be an array. - if not name.endswith('[]'): - answers[name] = get[key] - else: - name = name[:-2] - answers[name] = get.getlist(key) - - return answers - - class SelfAssessmentDescriptor(XmlDescriptor, EditingDescriptor): """ Module for putting raw html in a course