init commit: create skeleton from lab1
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
from typing import ClassVar, Literal
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, ValidationInfo, field_validator
|
||||
|
||||
|
||||
class Base(BaseModel):
|
||||
# from_attributes: схемы можно собирать прямо из ORM-объектов.
|
||||
model_config = ConfigDict(extra="forbid", from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
|
||||
|
||||
class Health(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
status: Literal["ok"]
|
||||
|
||||
|
||||
class BaseCreate(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
# Поля, где пробелы допустимы: пароль состоит из любых 12-128 code points.
|
||||
blank_allowed_fields: ClassVar[frozenset[str]] = frozenset({"password"})
|
||||
|
||||
@field_validator("*", mode="before")
|
||||
@classmethod
|
||||
def reject_blank_strings(cls, value: object, info: ValidationInfo) -> object:
|
||||
if info.field_name in cls.blank_allowed_fields:
|
||||
return value
|
||||
if isinstance(value, str) and not value.strip():
|
||||
raise ValueError("Строка не может состоять только из пробелов")
|
||||
return value
|
||||
|
||||
|
||||
class BasePage(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
Reference in New Issue
Block a user