trustpoint.views.base ===================== .. py:module:: trustpoint.views.base .. autoapi-nested-parse:: 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. Module Contents --------------- .. py:class:: IndexView(**kwargs) Bases: :py:obj:`django.views.generic.base.RedirectView` View that redirects to the index home page. .. py:attribute:: permanent :type: bool :value: False .. py:attribute:: pattern_name :type: str :value: 'home:dashboard' .. py:class:: ListInDetailView Bases: :py:obj:`django.views.generic.list.ListView`\ [\ :py:obj:`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. .. py:attribute:: detail_context_object_name :value: 'object' .. py:attribute:: detail_model :type: type[django.db.models.Model] .. py:method:: get(*args, **kwargs) Handle GET requests. .. py:method:: get_queryset_for_object() Get the queryset for the detail object. .. py:method:: get_object() Get the detail object from the URL pk parameter. .. py:method:: get_context_data(**kwargs) Add the detail object to the context. .. py:class:: SupportsGetContextData Bases: :py:obj:`Protocol` For typing to provide super().get_context_data(). .. py:method:: get_context_data(**kwargs) Get the context data. .. py:class:: ParentSupportsGetContextData Bases: :py:obj:`SupportsGetContextData`, :py:obj:`Protocol` For typing to provide super().get_context_data(). .. py:class:: SortableTableMixin Adds utility for sorting a ListView query by URL parameters. default_sort_param must be set in the view to specify default sorting order. .. py:attribute:: default_sort_param :type: str .. py:attribute:: request :type: django.http.HttpRequest .. py:attribute:: model :type: type[SortableTableMixin.T] .. py:attribute:: queryset :type: django.db.models.QuerySet[Any, Any] | None .. py:method:: get_queryset() Get the queryset and apply sorting based on URL parameters. .. py:method:: get_context_data(*args, **kwargs) Add sorting information to the context. .. py:class:: SortableTableFromListMixin 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. .. py:attribute:: default_sort_param :type: str .. py:attribute:: request :type: django.http.HttpRequest .. py:attribute:: model :type: type[django.db.models.Model] .. py:attribute:: queryset :type: list[dict[str, str]] | None .. py:method:: get_queryset() Get the queryset and apply sorting based on URL parameters. .. py:method:: get_context_data(*args, **kwargs) Add sorting information to the context. .. py:class:: ContextDataMixin Mixin to add context data from attributes prefixed with 'context_'. .. py:method:: get_context_data(**kwargs) 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. .. rubric:: 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. .. rubric:: 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' .. py:class:: BaseBulkDeleteView Bases: :py:obj:`django.views.generic.edit.FormMixin`\ [\ :py:obj:`django.forms.Form`\ ], :py:obj:`django.views.generic.list.BaseListView`\ [\ :py:obj:`Any`\ ] Base view for bulk deletion of objects. .. py:attribute:: queryset :type: Any .. py:attribute:: get_queryset :type: collections.abc.Callable[Ellipsis, django.db.models.QuerySet[Any, Any]] .. py:attribute:: success_url :type: str | django_stubs_ext.StrPromise | None :value: None .. py:attribute:: form_class .. py:method:: post(*_args, **_kwargs) Handles POST requests to the BulkDeleteView. .. py:method:: form_valid(_form) Delete the selected objects on valid form. .. py:method:: get_success_url() Returns the URL to redirect to after a successful deletion. .. py:class:: PrimaryKeyListFromPrimaryKeyString Utility class to parse primary keys from a URL string. .. py:method:: get_pks_as_list(pks) :staticmethod: Parse a slash-separated list of primary keys from a URL string. .. py:class:: PrimaryKeyQuerysetFromUrlMixin Bases: :py:obj:`PrimaryKeyListFromPrimaryKeyString` Mixin to retrieve a queryset based on primary keys provided in the URL. .. py:attribute:: kwargs :type: dict[str, Any] .. py:attribute:: model :type: type[django.db.models.Model] .. py:attribute:: queryset :type: django.db.models.QuerySet[Any, Any] | None .. py:method:: get_pks_path() Retrieve the primary key path from the URL parameters. .. py:method:: get_queryset() Retrieve a queryset based on primary keys provided in the URL. .. py:class:: BulkDeleteView Bases: :py:obj:`django.views.generic.list.MultipleObjectTemplateResponseMixin`, :py:obj:`PrimaryKeyQuerysetFromUrlMixin`, :py:obj:`BaseBulkDeleteView` View for bulk deletion of objects. .. py:attribute:: model :type: type[django.db.models.Model] .. py:method:: get_queryset() Return queryset for bulk delete. If no pks provided, return empty queryset. .. py:data:: THRESHOLD_LOGGER_HTTP_STATUS :type: int :value: 400 .. py:class:: LoggedHttpResponse(content = b'', status = None, *args, **kwargs) Bases: :py:obj:`django.http.HttpResponse`, :py:obj:`trustpoint.logger.LoggerMixin` Custom HttpResponse that logs and prints error messages automatically.