-
-
Notifications
You must be signed in to change notification settings - Fork 421
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
46 changed files
with
765 additions
and
508 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Config: | ||
|
||
- orm_mode -> from_attributes | ||
- allow_population_by_field_name -> populate_by_name |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
from typing import Any, Callable, Dict, Iterable, Optional, Type | ||
from typing import Any, Callable | ||
|
||
from django.core.files.uploadedfile import UploadedFile as DjangoUploadedFile | ||
from pydantic.fields import ModelField | ||
from pydantic.json_schema import JsonSchemaValue | ||
from pydantic_core import core_schema | ||
|
||
__all__ = ["UploadedFile"] | ||
|
||
|
||
class UploadedFile(DjangoUploadedFile): | ||
@classmethod | ||
def __get_validators__(cls: Type["UploadedFile"]) -> Iterable[Callable[..., Any]]: | ||
yield cls._validate | ||
def __get_pydantic_json_schema__(cls, core_schema, handler): | ||
# calling handler(core_schema) here raises an exception | ||
json_schema = {} | ||
json_schema.update(type="string", format="binary") | ||
return json_schema | ||
|
||
@classmethod | ||
def _validate(cls: Type["UploadedFile"], v: Any) -> Any: | ||
if not isinstance(v, DjangoUploadedFile): | ||
raise ValueError(f"Expected UploadFile, received: {type(v)}") | ||
return v | ||
def _validate(cls, __input_value: Any, _): | ||
if not isinstance(__input_value, DjangoUploadedFile): | ||
raise ValueError(f"Expected UploadFile, received: {type(__input_value)}") | ||
return __input_value | ||
|
||
@classmethod | ||
def __modify_schema__( | ||
cls, field_schema: Dict[str, Any], field: Optional[ModelField] = None | ||
) -> None: | ||
field_schema.update(type="string", format="binary") | ||
def __get_pydantic_core_schema__(cls, source, handler): | ||
return core_schema.general_plain_validator_function(cls._validate) |
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.