2
from typing import Optional, List, Any
4
from pydantic import BaseModel, UUID4, Field, AliasPath, AliasChoices, types, model_validator, \
6
from pydantic.config import JsonDict
7
from pydantic.fields import _EmptyKwargs, computed_field
8
from pydantic_core import PydanticUndefined
10
from ..schemas.list_schema import GenericListSchema
13
def validate_bollean(x):
14
if isinstance(x, list):
19
if isinstance(x, str):
27
bollean = typing.Annotated[bool, BeforeValidator(validate_bollean)]
30
class BasicModel(BaseModel):
32
Переопределяем для удобства
35
def check_condition(self, condition: tuple):
37
if len(condition) != 3:
38
raise ValueError('Неверное количество аргументов')
39
field1, operator, field2 = condition
44
fieldinfo = self.model_fields.get(field1)
46
raise ValueError(f'Неверное имя поля {field1}')
47
annotation = fieldinfo.annotation
48
field = getattr(self, field1)
49
if isinstance(field, Enum):
50
normalized_value = annotation(field2.lower())
52
normalized_value = field2
53
if field != normalized_value:
83
from_attributes = True
86
_Unset: Any = PydanticUndefined
90
default: Any = PydanticUndefined,
93
model: str | None = None,
94
readonly: bool | list = False,
98
default_factory: typing.Callable[[], Any] | None = _Unset,
99
alias: str | None = _Unset,
100
alias_priority: int | None = _Unset,
101
validation_alias: str | AliasPath | AliasChoices | None = _Unset,
102
serialization_alias: str | None = _Unset,
103
title: str | None = _Unset,
104
description: str | None = _Unset,
105
examples: list[Any] | None = _Unset,
106
exclude: bool | None = _Unset,
107
discriminator: str | types.Discriminator | None = _Unset,
108
json_schema_extra: JsonDict | typing.Callable[[JsonDict], None] | None = _Unset,
109
frozen: bool | None = _Unset,
110
validate_default: bool | None = _Unset,
112
init: bool | None = _Unset,
113
init_var: bool | None = _Unset,
114
kw_only: bool | None = _Unset,
115
pattern: str | None = _Unset,
116
strict: bool | None = _Unset,
117
gt: float | None = _Unset,
118
ge: float | None = _Unset,
119
lt: float | None = _Unset,
120
le: float | None = _Unset,
121
multiple_of: float | None = _Unset,
122
allow_inf_nan: bool | None = _Unset,
123
max_digits: int | None = _Unset,
124
decimal_places: int | None = _Unset,
125
min_length: int | None = _Unset,
126
max_length: int | None = _Unset,
127
union_mode: typing.Literal['smart', 'left_to_right'] = _Unset,
128
**extra: typing.Unpack[_EmptyKwargs],
131
Переопределяем для удобства
138
default_factory=default_factory,
140
alias_priority=alias_priority,
141
validation_alias=validation_alias,
142
serialization_alias=serialization_alias,
144
description=description,
147
discriminator=discriminator,
148
json_schema_extra=json_schema_extra,
150
validate_default=validate_default,
161
multiple_of=multiple_of,
162
allow_inf_nan=allow_inf_nan,
163
max_digits=max_digits,
164
decimal_places=decimal_places,
165
min_length=min_length,
166
max_length=max_length,
167
union_mode=union_mode,
172
class CountrySchema(BaseModel):
179
class CountryListSchema(GenericListSchema):
180
data: Optional[List[CountrySchema]]
183
class LocaleSchema(BaseModel):
187
territory: Optional[str | None] = None
193
class LocaleListSchema(GenericListSchema):
194
data: Optional[List[LocaleSchema]]
197
class CurrencySchema(BaseModel):
204
class CurrencyListSchema(GenericListSchema):
205
data: Optional[List[CurrencySchema]]
208
class PhoneSchema(BaseModel):
211
country_code_source: int
218
class ActionBaseSchame(BaseModel):
219
id: Optional[UUID4] = Field(default=None, title='Id', hidden=True)
220
ids: Optional[list[UUID4]] = Field(default=[], title='Ids', hidden=True)
221
lsn: Optional[int] = Field(default=0, title='Lsn', hidden=True)
222
vars: Optional[dict] = Field(default={}, title='Vars', hidden=True)
228
class ActionRescposeSchema(BaseModel):