Skip to content

Commit

Permalink
OC-13108 Fixed multilanguage form preview
Browse files Browse the repository at this point in the history
  • Loading branch information
gushil committed Dec 22, 2020
1 parent 7dfe632 commit 01ced84
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions kpi/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,7 @@ def _prepare_for_xml_pyxform_generation(self, content, id_string):
if 'id_string' not in settings.keys():
settings['id_string'] = id_string

settings['name'] = 'data'
content['settings'] = [settings]

if 'settings_header' not in content:
Expand Down Expand Up @@ -1287,14 +1288,15 @@ def _prepare_for_xml_pyxform_generation(self, content, id_string):

if 'survey' in content:
survey = content['survey']
translated = content.get('translated', [])

for survey_col_idx in range(len(survey)):
survey_col = survey[survey_col_idx]

if 'label' in survey_col:
if 'label' in survey_col and len(translated) > 0 and 'label' not in translated and type(survey_col['label']) is list:
survey_col['label'] = survey_col['label'][0]

if 'hint' in survey_col:
if 'hint' in survey_col and len(translated) > 0 and 'hint' not in translated and type(survey_col['hint']) is list:
survey_col['hint'] = survey_col['hint'][0]

if 'type' in survey_col:
Expand All @@ -1310,11 +1312,19 @@ def _prepare_for_xml_pyxform_generation(self, content, id_string):
del survey_col['select_one_from_file_filename']
survey_col['type'] = "{0} {1}".format(survey_col['type'], select_one_from_file_filename)

media_columns = ["audio", "image", "video", "media::audio", "media::image", "media::video"]
for media_column in media_columns:
if media_column in survey_col and type(survey_col[media_column]) is list and translations is not None:
for translation in translations:
survey_col['{}::{}'.format(media_column, translation)] = survey_col[media_column][translations.index(translation)]
if len(translated) > 0:
for translated_column in translated:
if translated_column in survey_col:
# logging.warning("translated_column {}".format(translated_column))
# logging.warning("translated_column value {}".format(survey_col[translated_column]))
translated_value = survey_col[translated_column]
del survey_col[translated_column]
for translation in translations:
column_value = translated_value[translations.index(translation)]
if translations.index(translation) == 0:
survey_col['{}'.format(translated_column, translation)] = u"{}".format(column_value)
else:
survey_col['{}::{}'.format(translated_column, translation)] = u"{}".format(column_value)

if 'survey_header' not in content:
content['survey_header'] = [{ col : "" for col in self.surveyCols}]
Expand Down Expand Up @@ -1346,6 +1356,7 @@ def generate_xml_from_source(self,
self._strip_kuids(source_copy)
self._settings_ensure_required_columns(source_copy)
self._adjust_content_media_column_before_generate_xml(source_copy)
# logging.warning("_adjust_content_media_column_before_generate_xml {}".format(source_copy))

warnings = []
details = {}
Expand All @@ -1362,9 +1373,11 @@ def generate_xml_from_source(self,

except PyXFormError as err:
self._prepare_for_xml_pyxform_generation(source_copy, id_string=id_string)

# logging.warning("_prepare_for_xml_pyxform_generation {}".format(source_copy))
survey_json = xls2json.workbook_to_json(source_copy)
# logging.warning("workbook_to_json {}".format(survey_json))
survey = builder.create_survey_element_from_dict(survey_json)
# logging.warning("create_survey_element_from_dict {}".format(survey))
xml = survey.to_xml()

details.update({
Expand Down

0 comments on commit 01ced84

Please sign in to comment.