From 3c31570829e08a237656087966347bdcd21f8abd Mon Sep 17 00:00:00 2001 From: Dickson Ukang'a Date: Sun, 2 Dec 2018 10:45:05 +0300 Subject: [PATCH] Use current() only for choice_filters --- pyxform/question.py | 4 ++-- pyxform/survey.py | 9 +++++---- pyxform/tests/test_output/yes_or_no_question.json | 3 ++- pyxform/tests_v1/test_repeat.py | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pyxform/question.py b/pyxform/question.py index 8e9936928..4f8efd67b 100644 --- a/pyxform/question.py +++ b/pyxform/question.py @@ -54,7 +54,7 @@ def xml_control(self): if self["query"]: choice_filter = self.get("choice_filter") query = "instance('" + self["query"] + "')/root/item" - choice_filter = survey.insert_xpaths(choice_filter, self) + choice_filter = survey.insert_xpaths(choice_filter, self, True) if choice_filter: query += "[" + choice_filter + "]" result.setAttribute("query", query) @@ -149,7 +149,7 @@ def xml_control(self): itemset = self["itemset"] itemset_label_ref = "jr:itext(itextId)" nodeset = "instance('" + itemset + "')/root/item" - choice_filter = survey.insert_xpaths(choice_filter, self) + choice_filter = survey.insert_xpaths(choice_filter, self, True) if choice_filter: nodeset += "[" + choice_filter + "]" diff --git a/pyxform/survey.py b/pyxform/survey.py index 4a695a76e..931659eca 100644 --- a/pyxform/survey.py +++ b/pyxform/survey.py @@ -702,7 +702,7 @@ def _setup_xpath_dictionary(self): else: self._xpath[element.name] = element.get_xpath() - def _var_repl_function(self, matchobj, context): + def _var_repl_function(self, matchobj, context, use_current=False): """ Given a dictionary of xpaths, return a function we can use to replace ${varname} with the xpath to varname. @@ -723,17 +723,18 @@ def _var_repl_function(self, matchobj, context): context.get_xpath()) if steps: ref_path = ref_path if ref_path.endswith(name) else "/%s" % name - return " " + "/".join([".."] * steps) + ref_path + " " + prefix = " current()/" if use_current else " " + return prefix + "/".join([".."] * steps) + ref_path + " " return " " + self._xpath[name] + " " - def insert_xpaths(self, text, context): + def insert_xpaths(self, text, context, use_current=False): """ Replace all instances of ${var} with the xpath to var. """ bracketed_tag = r"\$\{(.*?)\}" def _var_repl_function(matchobj): - return self._var_repl_function(matchobj, context) + return self._var_repl_function(matchobj, context, use_current) return re.sub(bracketed_tag, _var_repl_function, unicode(text)) diff --git a/pyxform/tests/test_output/yes_or_no_question.json b/pyxform/tests/test_output/yes_or_no_question.json index 2fdedd886..e95631377 100644 --- a/pyxform/tests/test_output/yes_or_no_question.json +++ b/pyxform/tests/test_output/yes_or_no_question.json @@ -22,7 +22,8 @@ } ], "type": "select one", - "name": "good_day", + "name": "good_day", + "parameters": {}, "label": { "english": "have you had a good day today?" } diff --git a/pyxform/tests_v1/test_repeat.py b/pyxform/tests_v1/test_repeat.py index 2e64a334c..f07caf165 100644 --- a/pyxform/tests_v1/test_repeat.py +++ b/pyxform/tests_v1/test_repeat.py @@ -151,7 +151,7 @@ def test_choice_filter_relative_path(self): # pylint: disable=invalid-name | | crop_list | kale | Kale | | """, # noqa pylint: disable=line-too-long xml__contains=[ - """""", # noqa pylint: disable=line-too-long - """""", # noqa pylint: disable=line-too-long + """""", # noqa pylint: disable=line-too-long + """""", # noqa pylint: disable=line-too-long ], )