-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
© Ocado Group | ||
Created on 05/11/2024 at 14:40:32(+00:00). | ||
""" | ||
|
||
from .drf import BaseRequest, Request | ||
from .http import BaseHttpRequest, HttpRequest | ||
from .wsgi import BaseWSGIRequest, WSGIRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
© Ocado Group | ||
Created on 05/11/2024 at 14:41:58(+00:00). | ||
Custom HttpRequest which hints to our custom types. | ||
""" | ||
|
||
import typing as t | ||
|
||
from django.contrib.auth.models import AbstractBaseUser, AnonymousUser | ||
from django.http import HttpRequest as _HttpRequest | ||
|
||
# pylint: disable-next=duplicate-code | ||
if t.TYPE_CHECKING: | ||
from ..user.models import User | ||
from ..user.models.session import SessionStore | ||
|
||
AnyUser = t.TypeVar("AnyUser", bound=User) | ||
else: | ||
AnyUser = t.TypeVar("AnyUser") | ||
|
||
AnyAbstractBaseUser = t.TypeVar("AnyAbstractBaseUser", bound=AbstractBaseUser) | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring | ||
class BaseHttpRequest(_HttpRequest, t.Generic[AnyAbstractBaseUser]): | ||
user: t.Union[AnyAbstractBaseUser, AnonymousUser] | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring | ||
class HttpRequest(BaseHttpRequest[AnyUser], t.Generic[AnyUser]): | ||
session: "SessionStore" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
© Ocado Group | ||
Created on 05/11/2024 at 14:41:58(+00:00). | ||
Custom WSGIRequest which hints to our custom types. | ||
""" | ||
|
||
import typing as t | ||
|
||
from django.contrib.auth.models import AbstractBaseUser, AnonymousUser | ||
from django.core.handlers.wsgi import WSGIRequest as _WSGIRequest | ||
|
||
# pylint: disable-next=duplicate-code | ||
if t.TYPE_CHECKING: | ||
from ..user.models import User | ||
from ..user.models.session import SessionStore | ||
|
||
AnyUser = t.TypeVar("AnyUser", bound=User) | ||
else: | ||
AnyUser = t.TypeVar("AnyUser") | ||
|
||
AnyAbstractBaseUser = t.TypeVar("AnyAbstractBaseUser", bound=AbstractBaseUser) | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring | ||
class BaseWSGIRequest(_WSGIRequest, t.Generic[AnyAbstractBaseUser]): | ||
user: t.Union[AnyAbstractBaseUser, AnonymousUser] | ||
|
||
|
||
# pylint: disable-next=missing-class-docstring | ||
class WSGIRequest(BaseWSGIRequest[AnyUser], t.Generic[AnyUser]): | ||
session: "SessionStore" |