(request, domain, app_id, key)
This function handles any request to switch two items in a list.
    Key tells us the list in question and must be one of
    'forms', 'modules', 'detail', or 'langs'. The two POST params
    'to' and 'from' give us the indicies of the items to be rearranged.
This function handles any request to switch two items in a list.
    Key tells us the list in question and must be one of
    'forms', 'modules', 'detail', or 'langs'. The two POST params
    'to' and 'from' give us the indicies of the items to be rearranged.
This function handles any request to switch two items in a list . Key tells us the list in question and must be one of forms modules detail or langs . The two POST params to and from give us the indicies of the items to be rearranged .
def rearrange(request, domain, app_id, key):
    """
    This function handles any request to switch two items in a list.
    Key tells us the list in question and must be one of
    'forms', 'modules', 'detail', or 'langs'. The two POST params
    'to' and 'from' give us the indicies of the items to be rearranged.

    """
    app = get_app(domain, app_id)
    ajax = json.loads(request.POST.get('ajax', 'false'))
    from_index, to_index = (int(x) for x in (request.POST['from'], request.POST['to']))
    resp = {}
    module_id = None

    try:
        if "forms" == key:
            from_module_uid = request.POST['from_module_uid']
            to_module_uid = request.POST['to_module_uid']
            app.rearrange_forms(from_module_uid, to_module_uid, from_index, to_index)
        elif "modules" == key:
            app.rearrange_modules(from_index, to_index)
    except IncompatibleFormTypeException as e:
        error = "{} {}".format(_('The form is incompatible with the destination menu and was not moved.'), str(e))
        if ajax:
            return json_response({'error': error}, status_code=400)
        messages.error(request, error)
        return back_to_main(request, domain, app_id=app_id, module_id=module_id)
    except (RearrangeError, ModuleNotFoundException):
        error = _(
            'Oops. '
            'Looks like you got out of sync with us. '
            'The sidebar has been updated, so please try again.'
        )
        if ajax:
            return json_response(error, status_code=400)
        messages.error(request, error)
        return back_to_main(request, domain, app_id=app_id, module_id=module_id)
    app.save(resp)
    if ajax:
        return HttpResponse(json.dumps(resp))
    else:
        return back_to_main(request, domain, app_id=app_id, module_id=module_id)
def rearrange ( request , domain , app_id , key ) : app = get_app ( domain , app_id ) ajax = json . loads ( request . POST . get ( 'ajax' , 'false' ) ) from_index , to_index = ( int ( x ) for x in ( request . POST [ 'from' ] , request . POST [ 'to' ] ) ) resp = { } module_id = None try : if "forms" == key : from_module_uid = request . POST [ 'from_module_uid' ] to_module_uid = request . POST [ 'to_module_uid' ] app . rearrange_forms ( from_module_uid , to_module_uid , from_index , to_index ) elif "modules" == key : app . rearrange_modules ( from_index , to_index ) except IncompatibleFormTypeException as e : error = "{} {}" . format ( _ ( 'The form is incompatible with the destination menu and was not moved.' ) , str ( e ) ) if ajax : return json_response ( { 'error' : error } , status_code = 400 ) messages . error ( request , error ) return back_to_main ( request , domain , app_id = app_id , module_id = module_id ) except ( RearrangeError , ModuleNotFoundException ) : error = _ ( 'Oops. ' 'Looks like you got out of sync with us. ' 'The sidebar has been updated, so please try again.' ) if ajax : return json_response ( error , status_code = 400 ) messages . error ( request , error ) return back_to_main ( request , domain , app_id = app_id , module_id = module_id ) app . save ( resp ) if ajax : return HttpResponse ( json . dumps ( resp ) ) else : return back_to_main ( request , domain , app_id = app_id , module_id = module_id )