mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 21:15:13 +00:00
* feat: i18n support * Optimize i18n * Update the locale in the code * Update the zh-CN file * Update the en-US file * Update the reload filter * Update locale success plugin value * Fix lint * Update pydantic error message translation * Update to minimal implementation * Fix minimal missing code
32 lines
823 B
Python
32 lines
823 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
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 __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
|
|
else timezone.to_str(x)
|
|
},
|
|
)
|