(app, workbook, sheet_name_to_unique_id, lang=None)
return msgs
Process the bulk upload file for the given app.
    We return these message tuples instead of calling them now to allow this
    function to be used independently of request objects.

    :return: Returns a list of message tuples. The first item in each tuple is
    a function like django.contrib.messages.error, and the second is a string.
Process the bulk upload file for the given app.
    We return these message tuples instead of calling them now to allow this
    function to be used independently of request objects.
Process the bulk upload file for the given app . We return these message tuples instead of calling them now to allow this function to be used independently of request objects .
def process_bulk_app_translation_upload(app, workbook, sheet_name_to_unique_id, lang=None):
    """
    Process the bulk upload file for the given app.
    We return these message tuples instead of calling them now to allow this
    function to be used independently of request objects.

    :return: Returns a list of message tuples. The first item in each tuple is
    a function like django.contrib.messages.error, and the second is a string.
    """

    def get_expected_headers(sheet_name):
        # This function does its best to return the headers we expect, based
        # on the current app, for an uploaded sheet. If the sheet is old, it
        # might not include the unique IDs of the modules/forms. In that case
        # `sheet_name_to_unique_id` will be empty and we fall back to using the
        # name of the sheet and hope that modules/forms have not been moved
        # since the sheet was originally downloaded.
        #
        # If a user created a new sheet, or renamed a sheet, or a form/module
        # has been deleted since this sheet was downloaded, then expected
        # headers will not be found. We return an empty list, and
        # `_check_for_sheet_error()` will handle it.
        if sheet_name in sheet_name_to_unique_id:
            unique_id = sheet_name_to_unique_id[sheet_name]
            if unique_id in expected_headers_by_id:
                return expected_headers_by_id[unique_id]
        return expected_headers_by_sheet_name.get(sheet_name, [])

    msgs = []
    single_sheet = is_single_sheet_workbook(workbook)
    expected_headers_by_sheet_name = {k: v for k, v in get_bulk_app_sheet_headers(app, single_sheet=single_sheet,
                                                                                  lang=lang)}
    expected_headers_by_id = {k: v for k, v in get_bulk_app_sheet_headers(app, single_sheet=single_sheet,
                                                                          lang=lang, by_id=True)}
    processed_sheets = set()

    for sheet in workbook.worksheets:
        expected_headers = get_expected_headers(sheet.worksheet.title)
        try:
            _check_for_sheet_error(sheet, expected_headers, processed_sheets)
        except BulkAppTranslationsException as e:
            msgs.append((messages.error, str(e)))
            continue

        processed_sheets.add(sheet.worksheet.title)

        warnings = _check_for_sheet_warnings(sheet, expected_headers)
        for warning in warnings:
            msgs.append((messages.warning, warning))

        if is_single_sheet(sheet.worksheet.title):
            msgs.extend(_process_single_sheet(app, sheet, names_map=sheet_name_to_unique_id, lang=lang))
        else:
            msgs.extend(_process_rows(app, sheet.worksheet.title, sheet, names_map=sheet_name_to_unique_id))

    msgs.append(
        (messages.success, _("App Translations Updated!"))
    )
    return msgs
def process_bulk_app_translation_upload ( app , workbook , sheet_name_to_unique_id , lang = None ) : def get_expected_headers ( sheet_name ) : # This function does its best to return the headers we expect, based # on the current app, for an uploaded sheet. If the sheet is old, it # might not include the unique IDs of the modules/forms. In that case # `sheet_name_to_unique_id` will be empty and we fall back to using the # name of the sheet and hope that modules/forms have not been moved # since the sheet was originally downloaded. # # If a user created a new sheet, or renamed a sheet, or a form/module # has been deleted since this sheet was downloaded, then expected # headers will not be found. We return an empty list, and # `_check_for_sheet_error()` will handle it. if sheet_name in sheet_name_to_unique_id : unique_id = sheet_name_to_unique_id [ sheet_name ] if unique_id in expected_headers_by_id : return expected_headers_by_id [ unique_id ] return expected_headers_by_sheet_name . get ( sheet_name , [ ] ) msgs = [ ] single_sheet = is_single_sheet_workbook ( workbook ) expected_headers_by_sheet_name = { k : v for k , v in get_bulk_app_sheet_headers ( app , single_sheet = single_sheet , lang = lang ) } expected_headers_by_id = { k : v for k , v in get_bulk_app_sheet_headers ( app , single_sheet = single_sheet , lang = lang , by_id = True ) } processed_sheets = set ( ) for sheet in workbook . worksheets : expected_headers = get_expected_headers ( sheet . worksheet . title ) try : _check_for_sheet_error ( sheet , expected_headers , processed_sheets ) except BulkAppTranslationsException as e : msgs . append ( ( messages . error , str ( e ) ) ) continue processed_sheets . add ( sheet . worksheet . title ) warnings = _check_for_sheet_warnings ( sheet , expected_headers ) for warning in warnings : msgs . append ( ( messages . warning , warning ) ) if is_single_sheet ( sheet . worksheet . title ) : msgs . extend ( _process_single_sheet ( app , sheet , names_map = sheet_name_to_unique_id , lang = lang ) ) else : msgs . extend ( _process_rows ( app , sheet . worksheet . title , sheet , names_map = sheet_name_to_unique_id ) ) msgs . append ( ( messages . success , _ ( "App Translations Updated!" ) ) ) return msgs