viewhelpers.formview.updateview — Update views

class UpdateViewMixin

Bases: django_cradmin.viewhelpers.formview.create_update_view_mixin.CreateUpdateViewMixin

Common mixin class for update views.

Note

You should import this class with from django_cradmin import viewhelpers, and refer to it using viewhelpers.formview.UpdateViewMixin.

get_pagetitle()

Get the page title (the title tag).

Defaults to Edit <verbose_name model>.

get_success_message(obj)

Override this to provide a success message.

The obj is the saved object.

Used by add_success_messages().

class WithinRoleUpdateView(**kwargs)

Bases: django_cradmin.viewhelpers.mixins.QuerysetForRoleMixin, django_cradmin.viewhelpers.formview.updateview.UpdateViewMixin, django.views.generic.edit.UpdateView, django_cradmin.viewhelpers.mixins.CommonCradminViewMixin, django_cradmin.javascriptregistry.viewmixin.WithinRoleViewMixin

Update view with the correct context data and sane base template for views where we have a cradmin role.

Note

You should import this class with from django_cradmin import viewhelpers, and refer to it using viewhelpers.formview.WithinRoleUpdateView.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

get_pagetitle()

Get the page title (the title tag).

Defaults to Edit <verbose_name model>.

get_success_message(obj)

Override this to provide a success message.

The obj is the saved object.

Used by add_success_messages().

get_context_data(**kwargs)

Insert the form into the context dict.

class UpdateRoleView(**kwargs)

Bases: django_cradmin.viewhelpers.formview.updateview.WithinRoleUpdateView

Extends UpdateView to streamline editing the current role object.

Just like UpdateView, but with the get_object and get_queryset_for_role methods implemented to edit the current role object.

Note

You should import this class with from django_cradmin import viewhelpers, and refer to it using viewhelpers.formview.UpdateRoleView.

Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.

get_object(queryset=None)

Returns the object the view is displaying.

By default this requires self.queryset and a pk or slug argument in the URLconf, but subclasses can override this to return any object.

get_queryset_for_role()

Get a queryset with all objects of self.model that the current role can access.

class RedirectToCreateIfDoesNotExistMixin

Bases: object

An update view mixin that redirects to a create view when the object requested does not exist.

You will typically use this for objects with a OneToOne relationship to the current role, but that may not exist. Then you would use something like:

class MyUpdateView(update.UpdateView, update.RedirectToCreateIfDoesNotExistMixin):
    def get_object(self, queryset=None):
        return self.get_queryset_for_role().get()

    def get_queryset_for_role(self):
        return self.get_model_class().objects.filter(
            someonetooneattr=self.request.cradmin_role)

And the view will automatically redirect to the create view if the object does not exist.

Note

You should import this class with from django_cradmin import viewhelpers, and refer to it using viewhelpers.formview.RedirectToCreateIfDoesNotExistMixin.

createview_appurl_name = 'create'

The viewname within this app for the create view. See get_createurl(). Defaults to create.

get_createurl()

Get the URL of the create view that you want to redirect to if the requested object does not exist.

Defaults to:

self.request.cradmin_app.reverse_appurl(self.createview_appurl_name)