Skip to content

Commit

Permalink
add lang_header parameter. lang_header can be used for specify the la…
Browse files Browse the repository at this point in the history
…nguage for header values in excel/csv export (you can have _xml header values and _default values for submits datas). If not set, lang arg override lang_header arg value. Need this PR : kobotoolbox/formpack#215
  • Loading branch information
jdugh committed Apr 29, 2020
1 parent 4b5abb6 commit 68fe555
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kpi/models/import_export_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ class ExportTask(ImportExportTask):
response values. Specify `_xml` to use question and choice names
instead of labels. Leave unset, or use `_default` for labels in
the default language
* `lang_header`: optional; the name of the translation to be used just for
headers values. Specify `_xml` to use question names in headers
instead of labels. Use `_default` for headers labels in the
default language. Leave unset for override it and use lang arg
value.
Need this PR : https://github.com/kobotoolbox/formpack/pull/215
* `hierarchy_in_labels`: optional; when `true`, include the labels for all
ancestor groups in each field label, separated by
`group_sep`. Defaults to `False`
Expand Down Expand Up @@ -462,10 +468,12 @@ def _build_export_options(self, pack):
group_sep = self.data.get('group_sep', '/')
translations = pack.available_translations
lang = self.data.get('lang', None) or next(iter(translations), None)
lang_header = self.data.get('lang_header', lang) or next(iter(translations), None)
try:
# If applicable, substitute the constants that formpack expects for
# friendlier language strings used by the API
lang = self.API_LANGUAGE_TO_FORMPACK_LANGUAGE[lang]
lang_header = self.API_LANGUAGE_TO_FORMPACK_LANGUAGE[lang_header]
except KeyError:
pass
tag_cols_for_header = self.data.get('tag_cols_for_header', ['hxl'])
Expand All @@ -478,6 +486,7 @@ def _build_export_options(self, pack):
'copy_fields': self.COPY_FIELDS,
'force_index': True,
'tag_cols_for_header': tag_cols_for_header,
'lang_header': lang_header,
}

def _record_last_submission_time(self, submission_stream):
Expand Down
1 change: 1 addition & 0 deletions kpi/views/v1/export_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def create(self, request, *args, **kwargs):
'lang',
'hierarchy_in_labels',
'fields_from_all_versions',
'lang_header',
)
task_data = {}
for opt in valid_options:
Expand Down

0 comments on commit 68fe555

Please sign in to comment.