-
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.
fix: various fixes for bulk logic and type hints (#65)
* only include read_only fields * user serializers correctly for remaining models * fix: extra_kwargs * fix: extra_kwargs, user * fix: extra_kwargs again * fix: custom base serializer * use string lib * add type hints * add type hint * custom data assertion
- Loading branch information
Showing
11 changed files
with
157 additions
and
48 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 |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
Created on 20/01/2024 at 11:19:12(+00:00). | ||
""" | ||
|
||
from .base import * | ||
from .model import * |
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,41 @@ | ||
""" | ||
© Ocado Group | ||
Created on 29/01/2024 at 14:27:09(+00:00). | ||
Base serializer. | ||
""" | ||
|
||
import typing as t | ||
|
||
from django.contrib.auth.models import AnonymousUser | ||
from rest_framework.serializers import BaseSerializer as _BaseSerializer | ||
|
||
from ..request import Request | ||
from ..user.models import User | ||
|
||
|
||
# pylint: disable-next=abstract-method | ||
class BaseSerializer(_BaseSerializer): | ||
"""Base serializer to be inherited by all other serializers.""" | ||
|
||
@property | ||
def request(self): | ||
"""The HTTP request that triggered the view.""" | ||
|
||
return t.cast(Request, self.context["request"]) | ||
|
||
@property | ||
def request_user(self): | ||
""" | ||
The user that made the request. Assumes the user has authenticated. | ||
""" | ||
|
||
return t.cast(User, self.request.user) | ||
|
||
@property | ||
def request_anon_user(self): | ||
""" | ||
The user that made the request. Assumes the user has not authenticated. | ||
""" | ||
|
||
return t.cast(AnonymousUser, self.request.user) |
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
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
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
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
Oops, something went wrong.