Mixins¶
- class cruditor.mixins.CruditorMixin[source]¶
Bases:
objectBase mixin for all Cruditor views. Provides common functionality for all views.
It is a good idea to have a own “base” mixin to configure the common options like
menu_title, the urls and templates.Usually you might have
required_permissionconfigured per-view.Title to use in templates / menu bar
Template name which is included to render the menu.
- extrahead_template_name = 'cruditor/includes/extrahead.html'[source]¶
Template used to include extra head stuff.
- model_verbose_name = None[source]¶
If not provided, Cruditor tries to look up the verbose name from
model.Meta
- dispatch(request, *args, **kwargs)[source]¶
Ensure the user is logged in (by calling ensure_logged_in` method). If the user is logged in, permissions are checked by calling
ensure_required_permission.
- get_cruditor_context(alternative_title=None, login_context=False)[source]¶
Provides some context for all Cruditor templates to render menu, header, breadcrumb and title buttons.
The method takes an optional argument
alternative_titleto override the default title fromget_titlemethod.
- get_title()[source]¶
Returns the title of the page. Uses view’s
titleproperty. If not set falls back tomenu_title.
- get_breadcrumb_title()[source]¶
By default, the breadcrumb title is the same as the page title. Calls
get_titleif not overwritten.
- get_breadcrumb()[source]¶
This method is expected to return a list of
Breadcrumbobejcts as a list.Every breadcrumb element is a
Breadcrumbinstance or a similar object with at least atitleproperty/key. If aurlkey/property is provided, the item is linked.
- get_titlebuttons()[source]¶
This method is expected to return None or a list of buttons to display in the title row of the page.
Every button element should be a
TitleButtoninstance or a similar object with at least alabel,urlandbutton_classproperty/key. Thebutton_classis used as a css class - pefixed with “btn-“.
- get_form_save_button_label()[source]¶
This method returns the label for the save button in templates that render a cruditor form. The default is “Save”. To ease overriding this value, the method also checks for a view class property named
form_save_button_label.
- get_model_verbose_name()[source]¶
Returns the verbose name of the handled object/item.
If
model_verbose_nameis set, the value is used. If not, Cruditor tries to get the verbose name from the model property (via Meta class). If no name is available at all, “Item” is returned.
- ensure_logged_in(request, *args, **kwargs)[source]¶
This method checks if the request user is logged in and has the right flags set (e.g.
is_staffifstaff_requiredis set in view).If user is logged in,
Trueis returned. If not,handle_not_logged_inis called.
- handle_not_logged_in(request, *args, **kwargs)[source]¶
This method is responsible to handle not logged-in users. By default, renders the Django login view using a Cruditor optimized template using the
login_form_classas Form.
- get_required_permission()[source]¶
Returns the required Django permissions required to access the view.
You might override the method to apply more complex rules on what permissions are required.
- class cruditor.mixins.FormViewMixin[source]¶
Bases:
objectMixin to add formset support to Django FormViews. To use formsets, you have to provide a set of formsets as a dict (or OrderedDict if you have more than one formset - just to have a defined ordering).
- get_formset_classes()[source]¶
This method returns the formset classes to render in the form view. By default, returns the
formset_classesproperty.
- get_formset_kwargs(formset_class)[source]¶
This method returns additional kwargs to initialize a formset. The formset_class is provided to ensure the method can return proper kwargs.
- get(request, *args, **kwargs)[source]¶
Extended get-method to render to form and all formsets properly initialized.
- post(request, *args, **kwargs)[source]¶
Extended version of the FormView.post method which validates the form and all configured formsets. If everything is valid,
form_validis called. If something is not valid,form_invalidis called.Both the form instance and all formset instances are provided to the called method. The form is passed as the first argument, the formsets are passed as keyword arguments using the formset key from
formset_classes.
- save_form(form, **formsets)[source]¶
This method is called from
form_validto actual save the data from the form and all formsets. All saving is done by default.