(request, workspace_id)
Clones dashboard workspace.
Clones dashboard workspace.
Clones dashboard workspace .
def clone_dashboard_workspace(request, workspace_id):
    """Clones dashboard workspace."""
    redirect_to = request.GET.get('next', None)

    try:
        workspace = DashboardWorkspace._default_manager.get(pk=workspace_id)
    except DashboardWorkspace.DoesNotExist:
        messages.info(request, _("Invalid dashboard workspace."))
        if redirect_to:
            return redirect(redirect_to)
        else:
            return redirect('dash.edit_dashboard')

    if not (workspace.is_cloneable or request.user.pk == workspace.user.pk):
        messages.info(request, _("You are not allowed to clone the given "
                                 "workspace."))
        if redirect_to:
            return redirect(redirect_to)
        else:
            return redirect('dash.edit_dashboard')

    cloned_workspace = clone_workspace(workspace, request.user)

    # Getting dashboard settings for the user. Then get users' layout.
    dashboard_settings = get_or_create_dashboard_settings(request.user)
    cloned_workspace_layout = get_layout(
        layout_uid=workspace.layout_uid, as_instance=True
    )
    layout = get_layout(
        layout_uid=dashboard_settings.layout_uid, as_instance=True
    )

    if (
        workspace.layout_uid == layout.uid
        or dashboard_settings.allow_different_layouts
    ):
        messages.info(
            request,
            _("Dashboard workspace `{0}` was successfully cloned into "
              "`{1}`.".format(workspace.name, cloned_workspace.name))
        )
        return redirect('dash.edit_dashboard', workspace=cloned_workspace.slug)

    else:
        messages.info(
            request,
            _("Dashboard workspace `{0}` was successfully cloned into `{1}` "
              "(layout `{2}`), however your active layout is `{3}`. You "
              "should switch to layout `{4}` (in your dashboard settings) "
              "in order to see the cloned workspace."
              "".format(workspace.name,
                        cloned_workspace.name,
                        cloned_workspace_layout.name,
                        layout.name,
                        cloned_workspace_layout.name))
        )
        return redirect('dash.edit_dashboard')
def clone_dashboard_workspace ( request , workspace_id ) : redirect_to = request . GET . get ( 'next' , None ) try : workspace = DashboardWorkspace . _default_manager . get ( pk = workspace_id ) except DashboardWorkspace . DoesNotExist : messages . info ( request , _ ( "Invalid dashboard workspace." ) ) if redirect_to : return redirect ( redirect_to ) else : return redirect ( 'dash.edit_dashboard' ) if not ( workspace . is_cloneable or request . user . pk == workspace . user . pk ) : messages . info ( request , _ ( "You are not allowed to clone the given " "workspace." ) ) if redirect_to : return redirect ( redirect_to ) else : return redirect ( 'dash.edit_dashboard' ) cloned_workspace = clone_workspace ( workspace , request . user ) # Getting dashboard settings for the user. Then get users' layout. dashboard_settings = get_or_create_dashboard_settings ( request . user ) cloned_workspace_layout = get_layout ( layout_uid = workspace . layout_uid , as_instance = True ) layout = get_layout ( layout_uid = dashboard_settings . layout_uid , as_instance = True ) if ( workspace . layout_uid == layout . uid or dashboard_settings . allow_different_layouts ) : messages . info ( request , _ ( "Dashboard workspace `{0}` was successfully cloned into " "`{1}`." . format ( workspace . name , cloned_workspace . name ) ) ) return redirect ( 'dash.edit_dashboard' , workspace = cloned_workspace . slug ) else : messages . info ( request , _ ( "Dashboard workspace `{0}` was successfully cloned into `{1}` " "(layout `{2}`), however your active layout is `{3}`. You " "should switch to layout `{4}` (in your dashboard settings) " "in order to see the cloned workspace." "" . format ( workspace . name , cloned_workspace . name , cloned_workspace_layout . name , layout . name , cloned_workspace_layout . name ) ) ) return redirect ( 'dash.edit_dashboard' )