From 68ca1251074158fd28203bf7adb4d1b583aa3450 Mon Sep 17 00:00:00 2001 From: Vik Paruchuri Date: Thu, 1 Nov 2012 11:13:14 -0400 Subject: [PATCH] working on save functionality to select only one --- .../xmodule/js/src/capa/display.coffee | 1 - .../js/src/selfassessment/display.coffee | 17 +++++++--- .../xmodule/xmodule/self_assessment_module.py | 34 +++++++++++++++---- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 6a3c719bb3..1c0ace9e59 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -209,7 +209,6 @@ class @Problem show: => if !@el.hasClass 'showed' Logger.log 'problem_show', problem: @id - alert(@url) $.postWithPrefix "#{@url}/problem_show", (response) => answers = response.answers $.each answers, (key, value) => diff --git a/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee b/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee index 592214734a..9c7f7faac4 100644 --- a/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/selfassessment/display.coffee @@ -3,6 +3,8 @@ $(document).on('click', 'section.sa-wrapper input#show', ( -> 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 input#answer').val() + alert(answer) + alert(final_url) $.post final_url, answer, (response) -> alert("posted") @@ -15,20 +17,25 @@ $(document).on('click', 'section.sa-wrapper input#save', ( -> answer=$('section.sa-wrapper input#answer').val() alert(answer) assessment=0 - assessment_correct=$('section.sa-wrapper input#assessment_correct').val() + assessment_correct=$('section.sa-wrapper input#assessment_correct').selected() alert(assessment_correct) - assessment_incorrect=$('section.sa-wrapper input#assessment_incorrect').val() + assessment_incorrect=$('section.sa-wrapper input#assessment_incorrect').selected() alert(assessment_incorrect) root = location.protocol + "//" + location.host post_url=$('section.sa-wrapper input#show').attr('url') - alert(post_url) final_url="/courses/MITx/6.002x/2012_Fall/modx/#{post_url}/sa_save" - alert(final_url) + + $('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) -> if response.success - $('p.rubric').replace(response.rubric) + $('section.sa_wrapper p#save_message').replace(response.message) alert("save") )); diff --git a/common/lib/xmodule/xmodule/self_assessment_module.py b/common/lib/xmodule/xmodule/self_assessment_module.py index 3508886918..d1d4c4205e 100644 --- a/common/lib/xmodule/xmodule/self_assessment_module.py +++ b/common/lib/xmodule/xmodule/self_assessment_module.py @@ -21,9 +21,9 @@ from xmodule.contentstore.content import XASSET_SRCREF_PREFIX, StaticContent log = logging.getLogger("mitx.courseware") -rubric_form=('
Correct
' - '' - 'Incorrect
') +rubric_form=('
Correct
' + '' + 'Incorrect



') def only_one(lst, default="", process=lambda x: x): """ @@ -61,7 +61,7 @@ class SelfAssessmentModule(XModule): instance_state=None, shared_state=None, **kwargs): XModule.__init__(self, system, location, definition, descriptor, instance_state, shared_state, **kwargs) - + dom2=etree.fromstring("" + self.definition['data'] + "") self.rubric=''.join([etree.tostring(child) for child in only_one(dom2.xpath('rubric'))]) self.problem=''.join([etree.tostring(child) for child in only_one(dom2.xpath('problem'))]) @@ -127,7 +127,7 @@ class SelfAssessmentModule(XModule): def show_rubric(self,get): - return {'success': True, 'rubric':self.rubric} + return {'success': True, 'rubric' : self.rubric} def save_problem(self, get): @@ -155,7 +155,29 @@ class SelfAssessmentModule(XModule): self.system.track_function('save_problem_succeed', event_info) - return {'success': True} + 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):