Skip to content

Commit

Permalink
Fixed <output> inside repeat has absolute path instead of relative.
Browse files Browse the repository at this point in the history
Addressing feedbacks.
  • Loading branch information
gushil committed Jul 17, 2020
1 parent 0e1fb2b commit 631ea08
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
29 changes: 10 additions & 19 deletions pyxform/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def _setup_choice_translations(name, choice_value, itext_id):
for d in element.get_translations(self.default_language):

translation_path = d["path"]
translation_key = "long"
translation_key = "form"

if "guidance_hint" in d["path"]:
translation_path = d["path"].replace("guidance_hint", "hint")
Expand All @@ -603,19 +603,14 @@ def _setup_choice_translations(name, choice_value, itext_id):
d["lang"]
].get(translation_path, {})

if "output_context" in d:
self._translations[d["lang"]][translation_path].update(
{
translation_key: {
"text": d["text"],
"output_context": d["output_context"],
}
self._translations[d["lang"]][translation_path].update(
{
translation_key: {
"text": d["text"],
"output_context": d["output_context"],
}
)
else:
self._translations[d["lang"]][translation_path].update(
{translation_key: d["text"]}
)
}
)

# This code sets up translations for choices in filtered selects.
for list_name, choice_list in self.choices.items():
Expand Down Expand Up @@ -734,11 +729,7 @@ def itext(self):
raise Exception()

for media_type, media_value in content.items():
if (
isinstance(media_value, dict)
and "text" in media_value
and "output_context" in media_value
):
if isinstance(media_value, dict):
value, output_inserted = self.insert_output_values(
media_value["text"], context=media_value["output_context"]
)
Expand All @@ -761,7 +752,7 @@ def itext(self):
)
continue

if media_type == "long":
if media_type == "form":
# I'm ignoring long types for now because I don't know
# how they are supposed to work.
itext_nodes.append(
Expand Down
3 changes: 3 additions & 0 deletions pyxform/survey_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def get_translations(self, default_language):
for lang, text in constraint_msg.items():
yield {
"path": self._translation_path("jr:constraintMsg"),
"output_context": self,
"lang": lang,
"text": text,
}
Expand All @@ -279,6 +280,7 @@ def get_translations(self, default_language):
for lang, text in required_msg.items():
yield {
"path": self._translation_path("jr:requiredMsg"),
"output_context": self,
"lang": lang,
"text": text,
}
Expand All @@ -287,6 +289,7 @@ def get_translations(self, default_language):
for lang, text in no_app_error_string.items():
yield {
"path": self._translation_path("jr:noAppErrorString"),
"output_context": self,
"lang": lang,
"text": text,
}
Expand Down
40 changes: 40 additions & 0 deletions pyxform/tests_v1/test_repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,46 @@ def test_output_with_translation_relative_path(self):
],
)

def test_output_with_guidance_hint_translation_relative_path(self):
md = """
| survey | | | | | |
| | type | name | label::English | guidance_hint::English | calculation |
| | begin repeat | member | | | |
| | calculate | pos | | | position(..) |
| | text | member_name | Name of ${pos} | More ${pos} | |
| | end repeat | | | | |
"""

self.assertPyxformXform(
md=md,
name="inside-repeat-relative-path",
xml__contains=[
'<translation lang="English">',
'<value> Name of <output value=" ../pos "/> </value>',
'<value form="guidance"> More <output value=" ../pos "/> </value>'
],
)

def test_output_with_multiple_translations_relative_path(self):
md = """
| survey | | | | | |
| | type | name | label::English | label::Indonesia | calculation |
| | begin repeat | member | | | |
| | calculate | pos | | | position(..) |
| | text | member_name | Name of ${pos} | Nama ${pos} | |
| | text | member_address | | Alamat | |
| | end repeat | | | | |
"""

self.assertPyxformXform(
md=md,
name="inside-repeat-relative-path",
xml__contains=[
'<translation lang="English">',
'<value> Name of <output value=" ../pos "/> </value>',
],
)

def test_hints_are_not_present_within_repeats(self):
"""Hints are not present within repeats"""
md = """
Expand Down

0 comments on commit 631ea08

Please sign in to comment.