trustpoint.views.base¶
Contains some global views that are not specific to a single app.
This module contains some general redirect and error views (e.g. 404) as well as specific mixins and view classes which can be used within the apps.
Attributes¶
Classes¶
View that redirects to the index home page. |
|
Helper view that combines a DetailView and a ListView. |
|
For typing to provide super().get_context_data(). |
|
For typing to provide super().get_context_data(). |
|
Adds utility for sorting a ListView query by URL parameters. |
|
Adds utility for sorting a ListView query by URL parameters. |
|
Base view for bulk deletion of objects. |
|
Mixin for responding with a template and list of objects. |
|
Custom HttpResponse that logs and prints error messages automatically. |
Module Contents¶
- class trustpoint.views.base.IndexView(**kwargs)[source]¶
Bases:
django.views.generic.base.RedirectViewView that redirects to the index home page.
- class trustpoint.views.base.ListInDetailView(**kwargs)[source]¶
Bases:
django.views.generic.list.ListViewHelper view that combines a DetailView and a ListView.
This is useful for displaying a list within a DetailView. Note that ‘model’ and ‘context_object_name’ refer to the ListView. Use ‘detail_model’ and ‘detail_context_object_name’ for the DetailView.
- class trustpoint.views.base.SupportsGetContextData[source]¶
Bases:
ProtocolFor typing to provide super().get_context_data().
- class trustpoint.views.base.ParentSupportsGetContextData[source]¶
Bases:
SupportsGetContextData,ProtocolFor typing to provide super().get_context_data().
- class trustpoint.views.base.SortableTableMixin[source]¶
Adds utility for sorting a ListView query by URL parameters.
default_sort_param must be set in the view to specify default sorting order.
- class trustpoint.views.base.SortableTableFromListMixin[source]¶
Adds utility for sorting a ListView query by URL parameters.
default_sort_param must be set in the view to specify default sorting order. Use instead of SortableTableMixin when you have a list of dicts instead of a Django queryset.
- static _sort_list_of_dicts(list_of_dicts, sort_param)[source]¶
Sorts a list of dictionaries by the given sort parameter.
- Parameters:
list_of_dicts (list[dict]) – List of dictionaries to sort.
sort_param (str) – The parameter to sort by. Prefix with ‘-’ for descending order.
- Returns:
The sorted list of dictionaries.
- Return type:
list[dict]
- class trustpoint.views.base.ContextDataMixin[source]¶
- get_context_data(**kwargs)[source]¶
Adds attributes prefixed with context_ to the context_data if it does not exist.
Note
If another succeeding class in the MRO has another get_context_data method, this method will be called after setting the attributes to the context_data.
Example
Lets consider context_page_category. Then the attribute page_category with the value of context_page_category is added to the context_data if page_category does not already exist in the context_data.
Example
- The following Mixin will add ‘page_category’: ‘pki’, and ‘page_name’: ‘endpoint_profiles’
to the context data.
- class EndpointProfilesExtraContextMixin(ContextDataMixin):
“””Mixin which adds context_data for the PKI -> Endpoint Profiles pages.”””
context_page_category = ‘pki’ context_page_name = ‘endpoint_profiles’
- Parameters:
kwargs (Any)
- Return type:
dict
- class trustpoint.views.base.BaseBulkDeleteView(**kwargs)[source]¶
Bases:
django.views.generic.edit.FormMixin,django.views.generic.list.BaseListViewBase view for bulk deletion of objects.
- get_queryset: collections.abc.Callable[source]¶
Return the list of items for this view.
The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.
- post(*_args, **_kwargs)[source]¶
Handles POST requests to the BulkDeleteView.
- Parameters:
_args (tuple[Any])
_kwargs (dict[str, Any])
- Return type:
django.http.HttpResponse
- class trustpoint.views.base.BulkDeleteView(**kwargs)[source]¶
Bases:
django.views.generic.list.MultipleObjectTemplateResponseMixin,PrimaryKeyQuerysetFromUrlMixin,BaseBulkDeleteViewMixin for responding with a template and list of objects.
- class trustpoint.views.base.LoggedHttpResponse(content=b'', status=None, *args, **kwargs)[source]¶
Bases:
django.http.HttpResponse,trustpoint.logger.LoggerMixinCustom HttpResponse that logs and prints error messages automatically.
- Parameters:
content (str | bytes)
status (int | None)
args (Any)
kwargs (Any)