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

IndexView

View that redirects to the index home page.

ListInDetailView

Helper view that combines a DetailView and a ListView.

SupportsGetContextData

For typing to provide super().get_context_data().

ParentSupportsGetContextData

For typing to provide super().get_context_data().

SortableTableMixin

Adds utility for sorting a ListView query by URL parameters.

SortableTableFromListMixin

Adds utility for sorting a ListView query by URL parameters.

ContextDataMixin

BaseBulkDeleteView

Base view for bulk deletion of objects.

PrimaryKeyListFromPrimaryKeyString

PrimaryKeyQuerysetFromUrlMixin

BulkDeleteView

Mixin for responding with a template and list of objects.

LoggedHttpResponse

Custom HttpResponse that logs and prints error messages automatically.

Module Contents

class trustpoint.views.base.IndexView(**kwargs)[source]

Bases: django.views.generic.base.RedirectView

View that redirects to the index home page.

permanent: bool = False[source]
pattern_name: str = 'home:dashboard'[source]
class trustpoint.views.base.ListInDetailView(**kwargs)[source]

Bases: django.views.generic.list.ListView

Helper 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.

detail_context_object_name = 'object'[source]
get(*args, **kwargs)[source]
Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

django.http.HttpResponse

get_queryset_for_object()[source]
get_object()[source]
Return type:

django.db.models.odel

get_context_data(**kwargs)[source]

Get the context for this view.

class trustpoint.views.base.SupportsGetContextData[source]

Bases: Protocol

For typing to provide super().get_context_data().

get_context_data(**kwargs)[source]
Parameters:

kwargs (Any)

Return type:

dict[str, Any]

class trustpoint.views.base.ParentSupportsGetContextData[source]

Bases: SupportsGetContextData, Protocol

For 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.

default_sort_param: str[source]
request: django.http.HttpRequest[source]
model: SortableTableMixin.T[source]
get_queryset()[source]
Return type:

django.db.models.QuerySet[Any]

get_context_data(*args, **kwargs)[source]
Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

dict[str, Any]

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]

get_queryset()[source]
Return type:

list[dict[str, str]]

get_context_data(*args, **kwargs)[source]
Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

dict[str, Any]

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.BaseListView

Base view for bulk deletion of objects.

queryset: Any[source]
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.

success_url = None[source]
form_class[source]
post(*_args, **_kwargs)[source]

Handles POST requests to the BulkDeleteView.

Parameters:
  • _args (tuple[Any])

  • _kwargs (dict[str, Any])

Return type:

django.http.HttpResponse

form_valid(_form)[source]

Delete the selected objects on valid form.

Parameters:

_form (form_class)

Return type:

django.http.HttpResponse

get_success_url()[source]

Returns the URL to redirect to after a successful deletion.

Return type:

str

class trustpoint.views.base.PrimaryKeyListFromPrimaryKeyString[source]
static get_pks_as_list(pks)[source]
Parameters:

pks (str)

Return type:

list[str]

class trustpoint.views.base.PrimaryKeyQuerysetFromUrlMixin[source]

Bases: PrimaryKeyListFromPrimaryKeyString

get_pks_path()[source]
Return type:

str

get_queryset()[source]
Return type:

None | django.db.models.QuerySet

class trustpoint.views.base.BulkDeleteView(**kwargs)[source]

Bases: django.views.generic.list.MultipleObjectTemplateResponseMixin, PrimaryKeyQuerysetFromUrlMixin, BaseBulkDeleteView

Mixin for responding with a template and list of objects.

trustpoint.views.base.THRESHOLD_LOGGER_HTTP_STATUS: int = 400[source]
class trustpoint.views.base.LoggedHttpResponse(content=b'', status=None, *args, **kwargs)[source]

Bases: django.http.HttpResponse, trustpoint.logger.LoggerMixin

Custom HttpResponse that logs and prints error messages automatically.

Parameters:
  • content (str | bytes)

  • status (int | None)

  • args (Any)

  • kwargs (Any)