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: