Smarter Authenticated List API View

class smarter.lib.drf.views.token_authentication_helpers.SmarterAuthenticatedListAPIView(*args, **kwargs)[source]

Bases: ListAPIView, SmarterRequestMixin

Smarter base class for DRF API list views that require authentication.

Does the following:

  • Adds SmarterRequestMixin to the view, so that base Smarter functionality is available to all subclasses.

  • Adds SmarterTokenAuthentication to the default SessionAuthentication for authentication.

  • Overrides Django’s logic for initializing the request object to ensure that SmarterRequestMixin is fully initialized before any other logic runs.

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

Initialize the view, and its SmarterRequestMixin.

DRF/Django’s View.__init__() does not call super().__init__(), so without this, SmarterRequestMixin.__init__() (and thus self._srm_ready and friends) would never be invoked, causing an AttributeError the first time self.srm_ready is accessed.

Parameters:
  • args – Passed to the view and to SmarterRequestMixin.

  • kwargs – Passed to the view. request, user, account and user_profile are passed to SmarterRequestMixin.

authentication_classes = [<class 'smarter.lib.drf.token_authentication.SmarterTokenAuthentication'>, <class 'rest_framework.authentication.SessionAuthentication'>]
property formatted_class_name[source]

The view’s dotted class name, formatted for log messages.

get_permissions()[source]

Return the view’s permissions, none for an OPTIONS request.

OPTIONS requests (CORS preflight, DRF metadata probes) never carry credentials, so they don’t require authentication.

Returns:

The permission instances, or an empty list for an OPTIONS request.

initial(request, *args, **kwargs)[source]

Set the SmarterRequestMixin’s request to the DRF request, then run DRF’s initial().

Parameters:
  • request (Request) – The incoming HTTP request.

  • args – Passed to DRF’s initial().

  • kwargs – Passed to DRF’s initial().

permission_classes = [<class 'smarter.lib.drf.views.helpers.SmarterAuthenticatedPermissionClass'>]