From 16a248b997d4ca9f4ac6b30d5e69df6f1dd384a2 Mon Sep 17 00:00:00 2001 From: Ahsan Ulhaq Date: Tue, 5 May 2015 15:38:10 +0500 Subject: [PATCH 1/2] Fieldset and legend solution is lost when edit Problem when user try to update a problem the fieldset and legend solution for that problem is lost because legend and fieldset are not added in the markdownToXml. So added new markups where fieldset is to be added and used ```>><<``` markup for legend. AC-103 --- common/lib/capa/capa/capa_problem.py | 23 +++++++++++- common/lib/capa/capa/inputtypes.py | 2 ++ .../lib/capa/capa/templates/choicegroup.html | 4 +-- .../lib/capa/capa/tests/test_html_render.py | 1 + .../capa/capa/tests/test_input_templates.py | 36 ++++++++++--------- common/lib/capa/capa/tests/test_inputtypes.py | 31 +++++++++++++++- .../xmodule/js/spec/problem/edit_spec.coffee | 23 ++++++------ .../xmodule/js/src/problem/edit.coffee | 4 ++- .../problem/checkboxes_response.yaml | 23 ++++++------ .../templates/problem/multiplechoice.yaml | 3 +- .../templates/problem/numericalresponse.yaml | 5 +-- .../templates/problem/optionresponse.yaml | 1 + .../templates/problem/string_response.yaml | 2 +- 13 files changed, 108 insertions(+), 50 deletions(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 48b07bd876..551aa2a68a 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -139,6 +139,7 @@ class LoncapaProblem(object): self.do_reset() self.problem_id = id self.capa_system = capa_system + self.question_label = "" state = state or {} @@ -732,6 +733,7 @@ class LoncapaProblem(object): 'status': status, 'id': input_id, 'input_state': self.input_state[input_id], + 'question_label': self.question_label if self.question_label else None, 'answervariable': answervariable, 'feedback': { 'message': msg, @@ -762,8 +764,12 @@ class LoncapaProblem(object): tree = etree.Element(problemtree.tag) for item in problemtree: item_xhtml = self._extract_html(item) + item_sibling = self.sibling_for_item(problemtree, item) if item_xhtml is not None: - tree.append(item_xhtml) + if item_xhtml.tag == "legend" and item_sibling is not None and item_sibling in self.responders: + self.question_label = item_xhtml.text + else: + tree.append(item_xhtml) if tree.tag in html_transforms: tree.tag = html_transforms[problemtree.tag]['tag'] @@ -834,3 +840,18 @@ class LoncapaProblem(object): for solution in tree.findall('.//solution'): solution.attrib['id'] = "%s_solution_%i" % (self.problem_id, solution_id) solution_id += 1 + + def sibling_for_item(self, tree, node): + """ + Check if node exist in problem tree and return next sibling if exist + else return None + """ + problem_tree = tree.xpath('//problem/*') + if node in problem_tree: + node_index = problem_tree.index(node) + try: + return problem_tree[node_index + 1] + except IndexError: + return None + else: + return None diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 9125451352..3a4430e45d 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -214,6 +214,7 @@ class InputTypeBase(object): self.hintmode = feedback.get('hintmode', None) self.input_state = state.get('input_state', {}) self.answervariable = state.get("answervariable", None) + self.question_label = state.get("question_label", None) # put hint above msg if it should be displayed if self.hintmode == 'always': @@ -313,6 +314,7 @@ class InputTypeBase(object): context.update(self._extra_context()) if self.answervariable: context.update({'answervariable': self.answervariable}) + context.update({'question_label': self.question_label if self.question_label is not None else ""}) return context def _extra_context(self): diff --git a/common/lib/capa/capa/templates/choicegroup.html b/common/lib/capa/capa/templates/choicegroup.html index 814fae6594..880b7f8bf5 100644 --- a/common/lib/capa/capa/templates/choicegroup.html +++ b/common/lib/capa/capa/templates/choicegroup.html @@ -17,8 +17,8 @@ % endif -
- +
+ ${question_label} % for choice_id, choice_description in choices: