Smarter Authenticated API View

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

Bases: APIView, SmarterRequestMixin

Smarter base class for DRF API detail 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.

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]

Finish initializing SmarterRequestMixin with the DRF request, then run DRF’s initial().

This is the earliest point in the DRF view lifecycle where the request object is available. Up to this point our SmarterRequestMixin, and AccountMixin classes are only partially initialized. This method takes care of the rest of the initialization.

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'>]
setup(request, *args, **kwargs)[source]

Set up the view for the request, and send the api_request_initiated signal.

Django calls this before dispatch().

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

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

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