def download_bulk_app_translations(request, domain, app_id): app = get_app(domain, app_id) headers = get_bulk_app_sheet_headers(app) rows = get_bulk_app_sheet_rows(app) temp = io.BytesIO() data = [(k, v) for k, v in six.iteritems(rows)] export_raw(headers, data, temp) filename = '{app_name} v.{app_version} - App Translations'.format( app_name=app.name, app_version=app.version) return export_response(temp, Format.XLS_2007, filename)
def _generate_expected_headers_and_rows(self): self.headers = { h[0]: h[1] for h in get_bulk_app_sheet_headers(self.app) } self.expected_rows = get_bulk_app_sheet_rows( self.app, exclude_module=lambda module: SKIP_TRANSFEX_STRING in module. comment, exclude_form=lambda form: SKIP_TRANSFEX_STRING in form.comment)
def test_sheet_headers(self): self.assertListEqual(get_bulk_app_sheet_headers(self.app), [ ['Modules_and_forms', ['Type', 'sheet_name', 'default_en', 'icon_filepath_en', 'audio_filepath_en', 'unique_id']], ['module1', ['case_property', 'list_or_detail', 'default_en']], ['module1_form1', ['label', 'default_en', 'image_en', 'audio_en', 'video_en']] ]) self.assertEqual(get_bulk_multimedia_sheet_headers('fra'), (('translations', ('menu or form', 'case_property', 'detail or label', 'fra', 'image', 'audio', 'video')),))
def test_bulk_app_sheet_rows(self): actual_headers = get_bulk_app_sheet_headers(self.app) actual_rows = get_bulk_app_sheet_rows(self.app) actual_workbook = [ {'name': title, 'rows': [dict(zip(headers, row)) for row in actual_rows[title]]} for title, headers in actual_headers ] for actual_sheet, expected_sheet in zip(actual_workbook, self.expected_workbook): self.assertEqual(actual_sheet, expected_sheet) self.assertEqual(actual_workbook, self.expected_workbook)
def _translation_data(self, app): # get the translations data from corehq.apps.translations.app_translations import get_bulk_app_sheet_rows # simply the rows of data per sheet name rows = get_bulk_app_sheet_rows( app, exclude_module=lambda module: SKIP_TRANSFEX_STRING in module. comment, exclude_form=lambda form: SKIP_TRANSFEX_STRING in form.comment) # get the translation data headers from corehq.apps.translations.app_translations import get_bulk_app_sheet_headers headers = get_bulk_app_sheet_headers( app, exclude_module=lambda module: SKIP_TRANSFEX_STRING in module. comment, exclude_form=lambda form: SKIP_TRANSFEX_STRING in form.comment) for header_row in headers: self.headers[header_row[0]] = header_row[1] self._set_sheet_name_to_module_or_form_mapping( rows[MODULES_AND_FORMS_SHEET_NAME]) return rows