(
    request,
    entry_id,
    template_name='dash/edit_dashboard_entry.html',
    template_name_ajax='dash/edit_dashboard_entry_ajax.html'
)
return render(request, template_name, context)
Edit dashboard entry.

    :param django.http.HttpRequest request:
    :param int entry_id: ID of the dashboard entry to edit.
    :param string template_name:
    :param string template_name_ajax: Template used for AJAX requests.
    :return django.http.HttpResponse:
Edit dashboard entry.
Edit dashboard entry .
def edit_dashboard_entry(
    request,
    entry_id,
    template_name='dash/edit_dashboard_entry.html',
    template_name_ajax='dash/edit_dashboard_entry_ajax.html'
):
    """Edit dashboard entry.

    :param django.http.HttpRequest request:
    :param int entry_id: ID of the dashboard entry to edit.
    :param string template_name:
    :param string template_name_ajax: Template used for AJAX requests.
    :return django.http.HttpResponse:
    """
    # Getting dashboard settings for the user. Then get users' layout.
    dashboard_settings = get_or_create_dashboard_settings(request.user)

    try:
        obj = DashboardEntry._default_manager.select_related(
            'workspace'
        ).get(
            pk=entry_id,
            user=request.user
        )
    except ObjectDoesNotExist as err:
        raise Http404(err)

    if obj.layout_uid:
        layout_uid = obj.layout_uid
    else:
        layout_uid = dashboard_settings.layout_uid

    layout = get_layout(layout_uid=layout_uid, as_instance=True)

    plugin = obj.get_plugin(fetch_related_data=True)
    plugin.request = request

    if plugin.edit_form_template:
        template_name = plugin.edit_form_template

    # Template context
    context = {
        'layout': layout,
        'dashboard_settings': dashboard_settings,
    }

    # If plugin has form, it is configurable which means we have to load the
    # plugin form and validate user input.
    plugin_form = plugin.get_form()
    if plugin_form:
        # If POST request and form data is valid, save the data and redirect
        # to the dashboard edit.
        if request.method == 'POST':
            form = plugin.get_initialised_edit_form_or_404(
                data=request.POST,
                files=request.FILES
            )
            if form.is_valid():
                # Saving the plugin form data.
                form.save_plugin_data(request=request)

                # Getting the plugin data.
                obj.plugin_data = form.get_plugin_data(request=request)

                # Save the object.
                obj.save()

                messages.info(
                    request,
                    _('The dashboard widget "{0}" was edited '
                      'successfully.').format(plugin.name)
                )

                # Redirect to edit dashboard view
                if obj.workspace:
                    return redirect(
                        'dash.edit_dashboard', workspace=obj.workspace.slug
                    )
                else:
                    return redirect('dash.edit_dashboard')

        else:
            form = plugin.get_initialised_edit_form_or_404()

        context.update({'form': form, 'plugin': plugin})

    if layout.edit_dashboard_entry_ajax_template_name:
        template_name_ajax = layout.edit_dashboard_entry_ajax_template_name

    context.update(
        {'edit_dashboard_entry_ajax_template_name': template_name_ajax}
    )

    if request.is_ajax():
        template_name = template_name_ajax
    elif layout.edit_dashboard_entry_template_name:
        template_name = layout.edit_dashboard_entry_template_name

    return render(request, template_name, context)
def edit_dashboard_entry ( request , entry_id , template_name = 'dash/edit_dashboard_entry.html' , template_name_ajax = 'dash/edit_dashboard_entry_ajax.html' ) : # Getting dashboard settings for the user. Then get users' layout. dashboard_settings = get_or_create_dashboard_settings ( request . user ) try : obj = DashboardEntry . _default_manager . select_related ( 'workspace' ) . get ( pk = entry_id , user = request . user ) except ObjectDoesNotExist as err : raise Http404 ( err ) if obj . layout_uid : layout_uid = obj . layout_uid else : layout_uid = dashboard_settings . layout_uid layout = get_layout ( layout_uid = layout_uid , as_instance = True ) plugin = obj . get_plugin ( fetch_related_data = True ) plugin . request = request if plugin . edit_form_template : template_name = plugin . edit_form_template # Template context context = { 'layout' : layout , 'dashboard_settings' : dashboard_settings , } # If plugin has form, it is configurable which means we have to load the # plugin form and validate user input. plugin_form = plugin . get_form ( ) if plugin_form : # If POST request and form data is valid, save the data and redirect # to the dashboard edit. if request . method == 'POST' : form = plugin . get_initialised_edit_form_or_404 ( data = request . POST , files = request . FILES ) if form . is_valid ( ) : # Saving the plugin form data. form . save_plugin_data ( request = request ) # Getting the plugin data. obj . plugin_data = form . get_plugin_data ( request = request ) # Save the object. obj . save ( ) messages . info ( request , _ ( 'The dashboard widget "{0}" was edited ' 'successfully.' ) . format ( plugin . name ) ) # Redirect to edit dashboard view if obj . workspace : return redirect ( 'dash.edit_dashboard' , workspace = obj . workspace . slug ) else : return redirect ( 'dash.edit_dashboard' ) else : form = plugin . get_initialised_edit_form_or_404 ( ) context . update ( { 'form' : form , 'plugin' : plugin } ) if layout . edit_dashboard_entry_ajax_template_name : template_name_ajax = layout . edit_dashboard_entry_ajax_template_name context . update ( { 'edit_dashboard_entry_ajax_template_name' : template_name_ajax } ) if request . is_ajax ( ) : template_name = template_name_ajax elif layout . edit_dashboard_entry_template_name : template_name = layout . edit_dashboard_entry_template_name return render ( request , template_name , context )