Skip to content

Commit

Permalink
init request
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Nov 6, 2024
1 parent 2492870 commit 77925a7
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion codeforlife/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,25 @@
# pylint: disable-next=missing-class-docstring
class BaseAPIView(_APIView, t.Generic[AnyBaseRequest]):
request: AnyBaseRequest
request_class: t.Type[AnyBaseRequest]

def initialize_request(self, request, *args, **kwargs):
# NOTE: Call to super has side effects and is required.
super().initialize_request(request, *args, **kwargs)

return self.request_class(
request=request,
parsers=self.get_parsers(),
authenticators=self.get_authenticators(),
negotiator=self.get_content_negotiator(),
parser_context=self.get_parser_context(request),
)


# pylint: disable-next=missing-class-docstring
class APIView(BaseAPIView[Request[RequestUser]], t.Generic[RequestUser]):
request_class = Request

@classmethod
def get_request_user_class(cls) -> t.Type[RequestUser]:
"""Get the request's user class.
Expand All @@ -45,7 +60,7 @@ def initialize_request(self, request, *args, **kwargs):
# NOTE: Call to super has side effects and is required.
super().initialize_request(request, *args, **kwargs)

return Request(
return self.request_class(
user_class=self.get_request_user_class(),
request=request,
parsers=self.get_parsers(),
Expand Down

0 comments on commit 77925a7

Please sign in to comment.