Skip to content

Commit

Permalink
Test that selects with media and choice filter generate single transl…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
DavisRayM committed Sep 9, 2020
1 parent 0963af6 commit 3ffb1ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
24 changes: 12 additions & 12 deletions pyxform/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,20 +711,20 @@ def _set_up_media_translations(media_dict, translation_key):
self._translations = defaultdict(dict) # pylint: disable=W0201

for survey_element in self.iter_descendants():
parent = survey_element.get("parent")
if parent and not parent.get("choice_filter"):
translation_key = survey_element.get_xpath() + ":label"
media_dict = survey_element.get("media")
_set_up_media_translations(media_dict, translation_key)
# parent = survey_element.get("parent")
# if parent and not parent.get("choice_filter"):
translation_key = survey_element.get_xpath() + ":label"
media_dict = survey_element.get("media")
_set_up_media_translations(media_dict, translation_key)

# This code sets up media for choices in filtered selects.
for list_name, choice_list in self.choices.items():
has_media = bool(choice_list[0].get("media"))
if not has_media:
continue
for idx, choice in zip(range(len(choice_list)), choice_list):
itext_id = "-".join([list_name, str(idx)])
_set_up_media_translations(choice.get("media"), itext_id)
# for list_name, choice_list in self.choices.items():
# has_media = bool(choice_list[0].get("media"))
# if not has_media:
# continue
# for idx, choice in zip(range(len(choice_list)), choice_list):
# itext_id = "-".join([list_name, str(idx)])
# _set_up_media_translations(choice.get("media"), itext_id)

def itext(self):
"""
Expand Down
6 changes: 5 additions & 1 deletion pyxform/tests_v1/test_inline_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_select_with_media_and_choice_filter_and_no_translations_generates_media
self,
):
"""
Selects with media and choice filter should generate itext fields.
Selects with media and choice filter should generate itext fields for the media.
"""
xform_md = """
| survey | | | | |
Expand All @@ -105,6 +105,10 @@ def test_select_with_media_and_choice_filter_and_no_translations_generates_media
"<itextId>mood-0</itextId>",
"<itextId>mood-1</itextId>",
],
model__excludes=[
'<text id="/data/enumerator_mood/h:label">',
'<text id="/data/enumerator_mood/s:label">',
],
xml__contains=['<label ref="jr:itext(itextId)"/>'],
xml__excludes=['<label ref="label"/>'],
)
Expand Down

0 comments on commit 3ffb1ac

Please sign in to comment.