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
-
You can use the following example problem as a model.
-
-
-
-
- Urdu
- Finnish
- Marathi
- French
- Hungarian
-
-
-
+
+
+
+ Urdu
+ Finnish
+ Marathi
+ French
+ Hungarian
+
+
Note: Make sure you select all of the correct options—there may be more than one!
diff --git a/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml b/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml
index 2aab5d17f9..72763ad060 100644
--- a/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml
@@ -15,6 +15,7 @@ metadata:
(x) Indonesia
( ) Russia
+
[explanation]
According to September 2014 estimates:
The population of Indonesia is approximately 250 million.
@@ -30,7 +31,6 @@ data: |
When you add the problem, be sure to select Settings
to specify a Display Name and other values that apply.
You can use the following example problem as a model.
-
@@ -40,7 +40,6 @@ data: |
Russia
-
Explanation
diff --git a/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml b/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml
index 8d886d3b30..3ed2c2ae8c 100644
--- a/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml
@@ -14,11 +14,12 @@ metadata:
>>How many miles away from Earth is the sun? Use scientific notation to answer.<<
= 9.3*10^6
- or= 9.296*10^6
+ or= 9.296*10^6
+
>>The square of what number is -100?<<
- = 10*i
+ = 10*i
[explanation]
The sun is 93,000,000, or 9.3*10^6, miles away from Earth.
diff --git a/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml b/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml
index 25de5fa3fc..f9f1964a75 100644
--- a/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml
@@ -14,6 +14,7 @@ metadata:
[[(India), Spain, China, Bermuda]]
+
[explanation]
India became an independent nation on August 15, 1947.
[explanation]
diff --git a/common/lib/xmodule/xmodule/templates/problem/string_response.yaml b/common/lib/xmodule/xmodule/templates/problem/string_response.yaml
index 701934f40e..2913dbca8c 100644
--- a/common/lib/xmodule/xmodule/templates/problem/string_response.yaml
+++ b/common/lib/xmodule/xmodule/templates/problem/string_response.yaml
@@ -14,7 +14,7 @@ metadata:
= Nanjing Higher Normal Institute
or= National Central University
or= Nanjing University
-
+
[explanation]
Nanjing Higher Normal Institute first admitted female students in 1920.
[explanation]
From c75526ea5e57b102d4d3b16aa423d16155940b66 Mon Sep 17 00:00:00 2001
From: Ahsan Ulhaq
Date: Tue, 19 May 2015 13:17:17 +0500
Subject: [PATCH 2/2] changes for failing label test
---
common/lib/capa/capa/tests/test_input_templates.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/common/lib/capa/capa/tests/test_input_templates.py b/common/lib/capa/capa/tests/test_input_templates.py
index 510a45ba74..f51244879e 100644
--- a/common/lib/capa/capa/tests/test_input_templates.py
+++ b/common/lib/capa/capa/tests/test_input_templates.py
@@ -126,7 +126,7 @@ class ChoiceGroupTemplateTest(TemplateTestCase):
self.context = {'id': '1',
'choices': choices,
'status': Status('correct'),
- 'question_label': '',
+ 'question_label': 'test',
'label': 'test',
'input_type': 'checkbox',
'name_array_suffix': '1',
@@ -343,8 +343,8 @@ class ChoiceGroupTemplateTest(TemplateTestCase):
def test_label(self):
xml = self.render_to_xml(self.context)
- xpath = "//fieldset[@aria-label='%s']" % self.context['label']
- self.assert_has_xpath(xml, xpath, self.context)
+ xpath = "//fieldset/legend"
+ self.assert_has_text(xml, xpath, self.context['question_label'])
class TextlineTemplateTest(TemplateTestCase):