(request, domain, app_id, module_unique_id)
return back_to_main(request, domain, app_id=app_id)
Deletes a module from an app
Deletes a module from an app
Deletes a module from an app
def delete_module(request, domain, app_id, module_unique_id):
    "Deletes a module from an app"
    deletion_records = []

    app = get_app(domain, app_id)
    try:
        module = app.get_module_by_unique_id(module_unique_id)
    except ModuleNotFoundException:
        return bail(request, domain, app_id)
    if module.get_child_modules():
        if module.module_type == 'shadow':
            # When deleting a shadow module, delete all the shadow-children
            for child_module in module.get_child_modules():
                deletion_records.append(app.delete_module(child_module.unique_id))
        else:
            messages.error(request, _('"{}" has sub-menus. You must remove these before '
                                      'you can delete it.').format(module.default_name()))
            return back_to_main(request, domain, app_id)

    shadow_children = [
        m.unique_id for m in app.get_modules()
        if m.module_type == 'shadow' and m.source_module_id == module_unique_id and m.root_module_id is not None
    ]
    for shadow_child in shadow_children:
        # We don't allow directly deleting or editing the source of a shadow
        # child, so we delete it when its source is deleted
        deletion_records.append(app.delete_module(shadow_child))

    deletion_records.append(app.delete_module(module_unique_id))
    restore_url = "{}?{}".format(
        reverse('undo_delete_module', args=[domain]),
        "&".join("record_id={}".format(record.get_id) for record in deletion_records)
    )
    deleted_names = ", ".join(record.module.default_name(app=app) for record in deletion_records)
    messages.success(
        request,
        _('You have deleted "{deleted_names}". <a href="{restore_url}" class="post-link">Undo</a>').format(
            deleted_names=deleted_names, restore_url=restore_url),
        extra_tags='html'
    )
    app.save()
    clear_xmlns_app_id_cache(domain)
    return back_to_main(request, domain, app_id=app_id)
def delete_module ( request , domain , app_id , module_unique_id ) : deletion_records = [ ] app = get_app ( domain , app_id ) try : module = app . get_module_by_unique_id ( module_unique_id ) except ModuleNotFoundException : return bail ( request , domain , app_id ) if module . get_child_modules ( ) : if module . module_type == 'shadow' : # When deleting a shadow module, delete all the shadow-children for child_module in module . get_child_modules ( ) : deletion_records . append ( app . delete_module ( child_module . unique_id ) ) else : messages . error ( request , _ ( '"{}" has sub-menus. You must remove these before ' 'you can delete it.' ) . format ( module . default_name ( ) ) ) return back_to_main ( request , domain , app_id ) shadow_children = [ m . unique_id for m in app . get_modules ( ) if m . module_type == 'shadow' and m . source_module_id == module_unique_id and m . root_module_id is not None ] for shadow_child in shadow_children : # We don't allow directly deleting or editing the source of a shadow # child, so we delete it when its source is deleted deletion_records . append ( app . delete_module ( shadow_child ) ) deletion_records . append ( app . delete_module ( module_unique_id ) ) restore_url = "{}?{}" . format ( reverse ( 'undo_delete_module' , args = [ domain ] ) , "&" . join ( "record_id={}" . format ( record . get_id ) for record in deletion_records ) ) deleted_names = ", " . join ( record . module . default_name ( app = app ) for record in deletion_records ) messages . success ( request , _ ( 'You have deleted "{deleted_names}". <a href="{restore_url}" class="post-link">Undo</a>' ) . format ( deleted_names = deleted_names , restore_url = restore_url ) , extra_tags = 'html' ) app . save ( ) clear_xmlns_app_id_cache ( domain ) return back_to_main ( request , domain , app_id = app_id )