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

Mixin to add context data from attributes prefixed with 'context_'.

BaseBulkDeleteView

Base view for bulk deletion of objects.

PrimaryKeyListFromPrimaryKeyString

Utility class to parse primary keys from a URL string.

PrimaryKeyQuerysetFromUrlMixin

Mixin to retrieve a queryset based on primary keys provided in the URL.

BulkDeleteView

View for bulk deletion 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[source]

Bases: django.views.generic.list.ListView[Any]

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]
detail_model: type[django.db.models.Model][source]
get(*args, **kwargs)[source]

Handle GET requests.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

django.http.HttpResponse

get_queryset_for_object()[source]

Get the queryset for the detail object.

Return type:

django.db.models.QuerySet[Any, Any]

get_object()[source]

Get the detail object from the URL pk parameter.

Return type:

django.db.models.Model

get_context_data(**kwargs)[source]

Add the detail object to the context.

Parameters:

kwargs (Any)

Return type:

dict[str, Any]

class trustpoint.views.base.SupportsGetContextData[source]

Bases: Protocol

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

get_context_data(**kwargs)[source]

Get the context data.

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: type[SortableTableMixin.T][source]
queryset: django.db.models.QuerySet[Any, Any] | None[source]
get_queryset()[source]

Get the queryset and apply sorting based on URL parameters.

Return type:

django.db.models.QuerySet[Any, Any]

get_context_data(*args, **kwargs)[source]

Add sorting information to the context.

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.

default_sort_param: str[source]
request: django.http.HttpRequest[source]
model: type[django.db.models.Model][source]
queryset: list[dict[str, str]] | None[source]
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[str, Any]]) – 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[str, Any]]

get_queryset()[source]

Get the queryset and apply sorting based on URL parameters.

Return type:

list[dict[str, str]]

get_context_data(*args, **kwargs)[source]

Add sorting information to the context.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

dict[str, Any]

class trustpoint.views.base.ContextDataMixin[source]

Mixin to add context data from attributes prefixed with ‘context_’.

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[str, Any]

class trustpoint.views.base.BaseBulkDeleteView[source]

Bases: django.views.generic.edit.FormMixin[django.forms.Form], django.views.generic.list.BaseListView[Any]

Base view for bulk deletion of objects.

queryset: Any[source]
get_queryset: collections.abc.Callable[Ellipsis, django.db.models.QuerySet[Any, Any]][source]
success_url: str | django_stubs_ext.StrPromise | None = 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 (django.forms.Form)

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]

Utility class to parse primary keys from a URL string.

static get_pks_as_list(pks)[source]

Parse a slash-separated list of primary keys from a URL string.

Parameters:

pks (str)

Return type:

list[str]

class trustpoint.views.base.PrimaryKeyQuerysetFromUrlMixin[source]

Bases: PrimaryKeyListFromPrimaryKeyString

Mixin to retrieve a queryset based on primary keys provided in the URL.

kwargs: dict[str, Any][source]
model: type[django.db.models.Model][source]
queryset: django.db.models.QuerySet[Any, Any] | None[source]
get_pks_path()[source]

Retrieve the primary key path from the URL parameters.

Return type:

str

get_queryset()[source]

Retrieve a queryset based on primary keys provided in the URL.

Return type:

django.db.models.QuerySet[Any, Any]

class trustpoint.views.base.BulkDeleteView[source]

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

View for bulk deletion of objects.

model: type[django.db.models.Model][source]
get_queryset()[source]

Return queryset for bulk delete. If no pks provided, return empty queryset.

Return type:

django.db.models.QuerySet[Any, Any]

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)