View Classes#

ViewSets#

class ModelViewSet(model: Optional[Type[ViewSetMixin]] = None, url_prefix: Optional[str] = None, url_namespace: Optional[str] = None, **kwargs)[source]#

Bases: object

A viewset to allow listing, creating, editing and deleting model instances.

create_view_class#

The view class to use for the index view; must be a subclass of wildewidgets.views.generic.CreateView.

alias of CreateView

delete_view_class#

The view class to use for the index view; must be a subclass of wildewidgets.views.generic.DeleteView.

alias of DeleteView

index_table_class#

The wildewidgets.widgets.tables.base.BaseDataTable subclass to use for the listing table

alias of LookupModelTable

index_view_class#

The view class to use for the index view; must be a subclass of wildewidgets.views.generic.IndexView.

alias of IndexView

table_ajax_view_class#

The view class to use as the AJAX JSON endpoint for the dataTable; must be a subclass of wildewidgets.views.generic.TableAJAXView.

alias of TableAJAXView

table_bulk_action_view_class#

The view class to use for the index view; must be a subclass of wildewidgets.views.generic.CreateView.

alias of TableBulkActionView

update_view_class#

The view class to use for the index view; must be a subclass of wildewidgets.views.generic.UpdateView.

alias of UpdateView

get_breadcrumbs(view_name: str) Optional[BreadcrumbBlock][source]#
get_index_table_kwargs()[source]#
get_url_name(view_name: str, namespace: bool = True) str[source]#

Returns the (possibly) namespaced URL name for the given view.

Parameters:

view_name

get_urlpatterns()[source]#
breadcrumbs_class: Optional[Type[BreadcrumbBlock]] = None#

Set this to your wildewidgets.widgets.navigation.BreadcrumbBlock class to manage breadcrumbs automatically.

property create_view#
property delete_view#
index_table_kwargs: Dict[str, Any] = {'buttons': True, 'page_length': 50, 'striped': True}#

A dictionary that we will use as the **kwargs for the constructor of table_class

property index_view#
model: Optional[Type[ViewSetMixin]] = None#

The model we’re describing in this view. It must have wildewidgets.models.ViewSetMixin in its class heirarchy

navbar_class: Optional[Type[Navbar]] = None#

The navbar to use. We’ll highlight our verbose name in any of the menus within the navbar

property table_ajax_view#
property table_bulk_action_view#
template_name: Optional[str] = None#

The template name to use for all views

property update_view#
url_namespace: Optional[str] = None#

The URL namespace to use for our view names. This should be set to the app_name set in the urls.py where this viewset’s patterns will be added to urlpatterns

url_prefix: Optional[str] = None#

The path prefix to use to organize our views.

View Mixins#

class GenericViewMixin(*args, **kwargs)[source]#

Bases: object

This class based view mixin adds some methods and attributes that our other generic views use.

get_breadcrumbs() Optional[BreadcrumbBlock][source]#

Add our title to the breadcrumbs and return the updated block.

Returns:

The breadcrumb block to use

get_client_ip() str[source]#

Return our user’s IP address. This will either be the leftmost IP address in our X-Forwarded-For header, or the REMOTE_ADDR header.

Returns:

Our user’s IP address

get_menu_item() Optional[str][source]#

Return the name of the main menu item to set active, which is the the appropriately capitalized verbose_name_plural for our model.

Returns:

The name of the main menu item to set active.

get_permissions_required() List[str][source]#

Overrides wildewidgets.views.permission.PermissionRequiredMixin.get_permissions_required.

Expand the permissions listed in required_model_permissions into full Django permission strings (e.g. appname.add_modelname and add them to the list of permissions already defined by our superclass.

Returns:

The list of Django user permission strings

breadcrumbs: Optional[BreadcrumbBlock] = None#

Set this to your wildewidgets.widgets.navigation.BreadcrumbBlock to manage breadcrumbs automatically.

logger: Any = <Logger wildewidgets.views.generic (WARNING)>#

Set this to the logger of your choice

property logging_extra: str#

Build some extra stuff to append to our logging statements:

  • add the user’s remote_ip

  • add the user’s username

  • add the pk of the object, if any

Returns:

A string to append to our log message

property model_logger_name: str#

Return a string we can use to identify this model in a log message.

property model_name: str#

Return our model name.

property model_verbose_name: str#

Return a string we can use to identify this model in a log message.

property model_verbose_name_plural: str#
required_model_permissions: List[str] = []#

Set this to the model permissions the user must have in order to be authorized for this view:

class GenericDatatableMixin[source]#

Bases: object

table_class#

The wildewidgets.widgets.tables.base.BaseDataTable subclass to use for the listing table

alias of LookupModelTable

get_table(*args, **kwargs) BaseDataTable[source]#
get_table_kwargs() Dict[str, Any][source]#

Return a dict that will be used as the **kwargs for constructing our table_class instance.

If there are no bulk_action form actions defined, define one for bulk deleting rows.

Returns:

Constructor kwargs for table_class

model: Optional[Type[ViewSetMixin]]#
table_kwargs: Dict[str, Any] = {'buttons': True, 'page_length': 25, 'striped': True}#

A dictionary that we will use as the **kwargs for the constructor of table_class

class WidgetInitKwargsMixin(*args, **kwargs)[source]#

Bases: object

convert_extra(extra_item, first=True)[source]#
get_decoded_extra_data(request)[source]#
get_encoded_extra_data()[source]#
class JSONResponseMixin[source]#

Bases: object

get(request, *args, **kwargs)[source]#
get_json_response(content: Any, **httpresponse_kwargs) HttpResponse[source]#

Construct an HttpResponse object.

post(*args, **kwargs)[source]#
render_to_response(context: Dict[str, Any]) str[source]#

Returns a JSON response containing ‘context’ as payload

is_clean: bool = False#
class StandardWidgetMixin[source]#

Bases: object

A class based view mixin for views that use a standard widget template. This is used with a template-less design.

The template used by your derived class should include at least the following:

{% extends "<your_base_template>.html" %}
{% load  wildewidgets %}

{% block title %}{{page_title}}{% endblock %}

{% block breadcrumb-items %}
{% if breadcrumbs %}
    {% wildewidgets breadcrumbs %}
{% endif %}
{% endblock %}

{% block content %}
{% wildewidgets content %}
{% endblock %}

The content block is where the content of the page is rendered. The breadcrumbs block is where the breadcrumbs are rendered.

An example derived class, which will be used by most of the views in the project:

class DemoStandardMixin(StandardWidgetMixin, NavbarMixin):
    template_name='core/standard.html'
    menu_class = DemoMenu

The DemoStandardMixin class is used in the following way:

class HomeView(DemoStandardMixin, TemplateView):
    menu_item = 'Home'

    def get_content(self):
        return HomeBlock()

    def get_breadcrumbs(self):
        breadcrumbs = DemoBaseBreadcrumbs()
        breadcrumbs.add_breadcrumb('Home')
        return breadcrumbs
get_breadcrumbs() Optional[BreadcrumbBlock][source]#
get_content()[source]#
get_context_data(**kwargs)[source]#
class PermissionRequiredMixin[source]#

Bases: AccessMixin

This class-based view mixin grants or denies access to a view based on a user’s group membership or specific permisisons.

check_permissions(groups_required: Optional[List[Group]] = None, permissions_required: Optional[List[str]] = None) bool[source]#

Check if the current user is authorized for our view.

Parameters:

request – the current request

Keyword Arguments:
Returns:

Return True if the user is authorized, False otherwise.

dispatch(request: HttpRequest, *args, **kwargs)[source]#
get_groups_required() List[Group][source]#
get_model_permissions(model: Model, perms: List[str]) List[str][source]#

Given a list of simple strings like view, add, change, etc. and a Django django.db.models.Model, return the list of actual permissions names that would apply to that model, e.g. for a model Foo in the django app core:

>>> PermissionMixin.get_model_permissions(Foo, ['add', 'change'])
['core.add_foo', 'core.change_foo']
Parameters:
  • model – the model for which to build permission strings

  • perms – the list of short permissions

Returns:

The fully formed permission strings

get_permissions_required() List[str][source]#
user_can_create() bool[source]#
user_can_delete() bool[source]#
user_can_update() bool[source]#
user_can_view() bool[source]#
groups_required: Optional[List[str]] = None#

Users who are members of the named Django auth groups will be permitted access to the view, and those who are not will be denied access.

model: Optional[Type[Model]]#

Used in conjunction with required_model_permissions, this is the model we want to act on. This should be set by our our subclass, which is why it is just a type declaration here. This is used by get_model_permissions

permissions_required: Optional[List[str]] = None#

Users who have any of the listed Django model permissions will be permitted access to the view.

required_model_permissions: Optional[List[str]] = None#

A list of simple strings like view, add, change, delete that represent actions that can be done on a model. This is used by py:meth:get_model_permissions

AJAX Views#

class JSONResponseView(**kwargs)[source]#

Bases: JSONResponseMixin, TemplateView

class JSONDataView(**kwargs)[source]#

Bases: View

get(request, *args, **kwargs)[source]#
get_context_data(**kwargs)[source]#
render_to_response(context, **response_kwargs)[source]#
class WildewidgetDispatch(*args, **kwargs)[source]#

Bases: WidgetInitKwargsMixin, View

dispatch(request, *args, **kwargs)[source]#

Generic Views#

class IndexView(*args, **kwargs)[source]#

Bases: LoginRequiredMixin, PermissionRequiredMixin, GenericViewMixin, GenericDatatableMixin, NavbarMixin, StandardWidgetMixin, TemplateView

get_content() Widget[source]#
get_title() str[source]#

Return our page title.

Returns:

The string to use as our page title.

model: Optional[Type[ViewSetMixin]] = None#

The model we’re describing in this view. It must have wildewidgets.models.ViewSetMixin in its class heirarchy

required_model_permissions: List[str] = ['view', 'add', 'change', 'delete']#

A list of simple strings like view, add, change, delete that represent actions that can be done on a model. This is used by py:meth:get_model_permissions

class TableAJAXView(*args, **kwargs)[source]#

Bases: LoginRequiredMixin, PermissionRequiredMixin, WidgetInitKwargsMixin, GenericDatatableMixin, View

dispatch(request, *args, **kwargs)[source]#
model: Optional[Type[ViewSetMixin]] = None#

The model we’re describing in this view. It must have wildewidgets.models.ViewSetMixin in its class heirarchy

required_model_permissions: List[str] = ['view', 'add', 'change', 'delete']#

A list of simple strings like view, add, change, delete that represent actions that can be done on a model. This is used by py:meth:get_model_permissions

class TableBulkActionView(*args, **kwargs)[source]#

Bases: LoginRequiredMixin, PermissionRequiredMixin, GenericViewMixin, GenericDatatableMixin, MessageMixin, TableActionFormView

process_delete_action(items: List[str]) None[source]#
logger: Any = <Logger wildewidgets.views.generic (WARNING)>#

Set this to the logger of your choice

model: Optional[Type[ViewSetMixin]] = None#

The model we’re describing in this view. It must have wildewidgets.models.ViewSetMixin in its class heirarchy

required_model_permissions: List[str] = ['delete']#

A list of simple strings like view, add, change, delete that represent actions that can be done on a model. This is used by py:meth:get_model_permissions

class CreateView(*args, **kwargs)[source]#

Bases: LoginRequiredMixin, PermissionRequiredMixin, FormInvalidMessageMixin, FormValidMessageMixin, GenericViewMixin, NavbarMixin, StandardWidgetMixin, CreateView

layout_widget#

Use this AbstractFormPageLayout subclass to render our page

alias of FormPageLayout

get_content() Widget[source]#
get_form_class() Type[BaseModelForm][source]#

Return the form class to use in this view.

get_form_invalid_message()[source]#

Validate that form_invalid_message is set and is either a unicode or str object.

get_form_valid_message()[source]#

Validate that form_valid_message is set and is either a unicode or str object.

get_title() str[source]#

Return our page title.

Returns:

The string to use as our page title.

required_model_permissions: List[str] = ['add']#

A list of simple strings like view, add, change, delete that represent actions that can be done on a model. This is used by py:meth:get_model_permissions

class UpdateView(*args, **kwargs)[source]#

Bases: LoginRequiredMixin, PermissionRequiredMixin, FormInvalidMessageMixin, FormValidMessageMixin, GenericViewMixin, NavbarMixin, StandardWidgetMixin, UpdateView

layout_widget#

Use this AbstractFormPageLayout subclass to render our page

alias of FormPageLayout

get_content() Widget[source]#
get_form_class() Type[BaseModelForm][source]#

Return the form class to use in this view.

get_form_invalid_message()[source]#

Validate that form_invalid_message is set and is either a unicode or str object.

get_form_valid_message()[source]#

Validate that form_valid_message is set and is either a unicode or str object.

get_title() str[source]#

Return our page title.

Returns:

The string to use as our page title.

required_model_permissions: List[str] = ['change']#

A list of simple strings like view, add, change, delete that represent actions that can be done on a model. This is used by py:meth:get_model_permissions

class DeleteView(*args, **kwargs)[source]#

Bases: LoginRequiredMixin, PermissionRequiredMixin, GenericViewMixin, FormInvalidMessageMixin, FormValidMessageMixin, BaseDeleteView

form_invalid(form: BaseModelForm) HttpResponse[source]#

If the form is invalid, render the invalid form.

get_form_class() Type[BaseModelForm][source]#

Return the form class to use.

get_form_invalid_message()[source]#

Validate that form_invalid_message is set and is either a unicode or str object.

get_form_valid_message()[source]#

Validate that form_valid_message is set and is either a unicode or str object.

http_method_names: List[str] = ['post']#
model: Optional[Type[ViewSetMixin]] = None#

Used in conjunction with required_model_permissions, this is the model we want to act on. This should be set by our our subclass, which is why it is just a type declaration here. This is used by get_model_permissions

required_model_permissions: List[str] = ['delete']#

A list of simple strings like view, add, change, delete that represent actions that can be done on a model. This is used by py:meth:get_model_permissions