Files
Wu Clan 5762834744 Update the ruff rules and format the code (#846)
* Update the ruff rules and format the code

* Update the per-file-ignores

* Update the ci

* Update rules

* Fix codes

* Fix pagination

* Update rules
2025-10-10 19:02:49 +08:00

30 lines
805 B
Python

from datetime import datetime
from typing import Annotated
from pydantic import BaseModel, ConfigDict, EmailStr, Field, validate_email
from backend.utils.timezone import timezone
CustomPhoneNumber = Annotated[str, Field(pattern=r'^1[3-9]\d{9}$')]
class CustomEmailStr(EmailStr):
"""自定义邮箱类型"""
@classmethod
def _validate(cls, input_value: str, /) -> str:
return None if not input_value else validate_email(input_value)[1]
class SchemaBase(BaseModel):
"""基础模型配置"""
model_config = ConfigDict(
use_enum_values=True,
json_encoders={
datetime: lambda x: timezone.to_str(timezone.from_datetime(x))
if x.tzinfo is not None and x.tzinfo != timezone.tz_info
else timezone.to_str(x),
},
)