Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lang_header parameter for specify language header values in export #2643

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lang_header = self.data.get('lang_header', lang) or next(iter(translations), None)
lang_header = self.data.get('lang_header', lang)

because lang is the fallback value, and it's set in the line above, we don't need a second fallback value

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