viewhelpers.mixins — View mixin classes

class QuerysetForRoleMixin

Bases: object

Common mixin class for views that query for items limited to items accessible by the current cradmin role.

Note

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

get_queryset_for_role()

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

get_queryset()

DO NOT override this. Override get_queryset_for_role() instead.

class CommonCradminViewMixin

Bases: object

Common mixin class for all cradmin view classes.

Note

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

add_breadcrumb_list_items(breadcrumb_item_list)

Add items to the breadcrumb item list.

If you completely override the get_breadcrumb_item_list_renderable() method without calling super (or calling this method explicitly), this method will have no effect.

Examples

Simple example:

def add_breadcrumb_list_items(self, breadcrumb_item_list):
    breadcrumb_item_list.append(url='#', label='Test')
Parameters:breadcrumb_item_list (django_cradmin.crbreadcrumb.BreadcrumbItemList) – The breadcrumb item list to add items to.
get_breadcrumb_item_list_renderable()

Get a breadcrumb item list renderable to use when rendering the template for this view.

By default, this just uses request.cradmin_app.get_breadcrumb_item_list_renderable() (see django_cradmin.crapp.App.get_breadcrumb_item_list_renderable()).

You will normally only want to override this if you want to customize how breadcrumbs are rendered. If you just need to add items to the breadcrumb item list, override add_breadcrumb_list_items().

If you override this, remember that the breadcrumb item list from request.cradmin_app.get_breadcrumb_item_list_renderable() can be None, so if you use that method you have to remember to handle this.

Returns:
A breadcrumb item list renderable object
or None.
Return type:django_cradmin.crbreadcrumb.BreadcrumbItemList
add_common_view_mixin_data_to_context(context)

Call this to add common template context variables to the provided context.

Do not override this in subclasses, but if you create a class that uses this mixin, you must call this in your get_context_data()-method.

Parameters:context (dict) – A template context.