(app_source, ids_map, update_all=True)
return app_source
Accepts an ids_map translating IDs in app_source to the desired replacement
    ID. Form IDs not present in ids_map will be given new random UUIDs.
Accepts an ids_map translating IDs in app_source to the desired replacement
    ID. Form IDs not present in ids_map will be given new random UUIDs.
Accepts an ids_map translating IDs in app_source to the desired replacement ID . Form IDs not present in ids_map will be given new random UUIDs .
def update_form_unique_ids(app_source, ids_map, update_all=True):
    """
    Accepts an ids_map translating IDs in app_source to the desired replacement
    ID. Form IDs not present in ids_map will be given new random UUIDs.
    """
    from corehq.apps.app_manager.models import form_id_references, jsonpath_update

    app_source = deepcopy(app_source)
    attachments = app_source['_attachments']

    def change_form_unique_id(form, old_id, new_id):
        form['unique_id'] = new_id
        if f"{old_id}.xml" in attachments:
            attachments[f"{new_id}.xml"] = attachments.pop(f"{old_id}.xml")

    # once Application.wrap includes deleting user_registration
    # we can remove this
    if 'user_registration' in app_source:
        del app_source['user_registration']

    new_ids_by_old = {}
    for m, module in enumerate(app_source['modules']):
        for f, form in enumerate(module['forms']):
            old_id = form['unique_id']
            if update_all or old_id in ids_map:
                new_id = ids_map.get(old_id, uuid.uuid4().hex)
                new_ids_by_old[old_id] = new_id
                change_form_unique_id(form, old_id, new_id)

    for reference_path in form_id_references:
        for reference in reference_path.find(app_source):
            if reference.value in new_ids_by_old:
                jsonpath_update(reference, new_ids_by_old[reference.value])

    return app_source
def update_form_unique_ids ( app_source , ids_map , update_all = True ) : from corehq . apps . app_manager . models import form_id_references , jsonpath_update app_source = deepcopy ( app_source ) attachments = app_source [ '_attachments' ] def change_form_unique_id ( form , old_id , new_id ) : form [ 'unique_id' ] = new_id if f"{old_id}.xml" in attachments : attachments [ f"{new_id}.xml" ] = attachments . pop ( f"{old_id}.xml" ) # once Application.wrap includes deleting user_registration # we can remove this if 'user_registration' in app_source : del app_source [ 'user_registration' ] new_ids_by_old = { } for m , module in enumerate ( app_source [ 'modules' ] ) : for f , form in enumerate ( module [ 'forms' ] ) : old_id = form [ 'unique_id' ] if update_all or old_id in ids_map : new_id = ids_map . get ( old_id , uuid . uuid4 ( ) . hex ) new_ids_by_old [ old_id ] = new_id change_form_unique_id ( form , old_id , new_id ) for reference_path in form_id_references : for reference in reference_path . find ( app_source ) : if reference . value in new_ids_by_old : jsonpath_update ( reference , new_ids_by_old [ reference . value ] ) return app_source