From fe954ca1c7cbbb541e644c8e987e5b2d9a4512e9 Mon Sep 17 00:00:00 2001 From: kimth Date: Mon, 13 Aug 2012 10:46:01 -0400 Subject: [PATCH 1/3] Unbreak frontend polling --- common/lib/xmodule/xmodule/js/src/capa/display.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/capa/display.coffee b/common/lib/xmodule/xmodule/js/src/capa/display.coffee index 6bdd8e1c36..d61813ce58 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/capa/display.coffee @@ -40,8 +40,9 @@ class @Problem poll: => $.postWithPrefix "#{@url}/problem_get", (response) => @el.html(response.html) - @executeProblemScripts() - @bind() + @executeProblemScripts () => + @setupInputTypes() + @bind() @queued_items = @$(".xqueue") if @queued_items.length == 0 From 99e7711acad272d5087d47d4e68d8b959d0a7b46 Mon Sep 17 00:00:00 2001 From: kimth Date: Mon, 13 Aug 2012 15:48:33 -0400 Subject: [PATCH 2/3] Generic CodeResponse XML (+ support for old ExternalResponse XML) --- common/lib/capa/capa/capa_problem.py | 4 +- common/lib/capa/capa/responsetypes.py | 73 +++++++++++++++++++-------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 3d68d2d604..82eb330174 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -41,7 +41,7 @@ response_tag_dict = dict([(x.response_tag, x) for x in responsetypes.__all__]) entry_types = ['textline', 'schematic', 'textbox', 'imageinput', 'optioninput', 'choicegroup', 'radiogroup', 'checkboxgroup', 'filesubmission', 'javascriptinput'] solution_types = ['solution'] # extra things displayed after "show answers" is pressed -response_properties = ["responseparam", "answer"] # these get captured as student responses +response_properties = ["codeparam", "responseparam", "answer"] # these get captured as student responses # special problem tags which should be turned into innocuous HTML html_transforms = {'problem': {'tag': 'div'}, @@ -57,7 +57,7 @@ global_context = {'random': random, 'eia': eia} # These should be removed from HTML output, including all subelements -html_problem_semantics = ["responseparam", "answer", "script", "hintgroup"] +html_problem_semantics = ["codeparam", "responseparam", "answer", "script", "hintgroup"] log = logging.getLogger('mitx.' + __name__) diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 4c6627b352..5f23093099 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -1024,41 +1024,70 @@ class CodeResponse(LoncapaResponse): self.url = xml.get('url', None) # XML can override external resource (grader/queue) URL self.queue_name = xml.get('queuename', self.system.xqueue['default_queuename']) - self._parse_externalresponse_xml() + # VS[compat]: + # Check if XML uses the ExternalResponse format or the generic CodeResponse format + codeparam = self.xml.find('codeparam') + if codeparam is None: + self._parse_externalresponse_xml() + else: + self._parse_coderesponse_xml(codeparam) + + def _parse_coderesponse_xml(self,codeparam): + ''' + Parse the new CodeResponse XML format. When successful, sets: + self.initial_display + self.answer (an answer to display to the student in the LMS) + self.payload + ''' + # Note that CodeResponse is agnostic to the specific contents of grader_payload + grader_payload = codeparam.find('grader_payload') + grader_payload = grader_payload.text if grader_payload is not None else '' + self.payload = {'grader_payload': grader_payload} + + answer_display = codeparam.find('answer_display') + if answer_display is not None: + self.answer = answer_display.text + else: + self.answer = 'No answer provided.' + + initial_display = codeparam.find('initial_display') + if initial_display is not None: + self.initial_display = initial_display.text + else: + self.initial_display = '' def _parse_externalresponse_xml(self): ''' VS[compat]: Suppport for old ExternalResponse XML format. When successful, sets: - self.code - self.tests - self.answer self.initial_display + self.answer (an answer to display to the student in the LMS) + self.payload ''' answer = self.xml.find('answer') if answer is not None: answer_src = answer.get('src') if answer_src is not None: - self.code = self.system.filesystem.open('src/' + answer_src).read() + code = self.system.filesystem.open('src/' + answer_src).read() else: - self.code = answer.text + code = answer.text else: # no stanza; get code from