mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
chore: update .gitignore and enhance docstrings across multiple files
- Added *.pyc and *.pyo to .gitignore to prevent compiled Python files from being tracked. - Improved docstrings in various modules, providing clearer descriptions of functions, parameters, and return values to enhance code readability and maintainability.
This commit is contained in:
@@ -11,7 +11,15 @@ class DeptCRUD(CRUDBase[DeptModel, DeptCreateSchema, DeptUpdateSchema]):
|
||||
"""部门模块数据层"""
|
||||
|
||||
def __init__(self, auth: AuthSchema) -> None:
|
||||
"""初始化部门CRUD"""
|
||||
"""
|
||||
初始化部门数据层。
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息模型(含 DB 会话等上下文)。
|
||||
|
||||
返回:
|
||||
- None
|
||||
"""
|
||||
self.auth = auth
|
||||
super().__init__(model=DeptModel, auth=auth)
|
||||
|
||||
|
||||
@@ -22,6 +22,18 @@ class DeptCreateSchema(BaseModel):
|
||||
@field_validator("name")
|
||||
@classmethod
|
||||
def validate_name(cls, value: str):
|
||||
"""
|
||||
校验并规范化部门名称(去空格、非空)。
|
||||
|
||||
参数:
|
||||
- value (str): 部门名称。
|
||||
|
||||
返回:
|
||||
- str: 规范化后的部门名称。
|
||||
|
||||
异常:
|
||||
- ValueError: 部门名称为空时抛出。
|
||||
"""
|
||||
if not value or len(value.strip()) == 0:
|
||||
raise ValueError("部门名称不能为空")
|
||||
value = value.replace(" ", "")
|
||||
@@ -30,6 +42,18 @@ class DeptCreateSchema(BaseModel):
|
||||
@field_validator("code")
|
||||
@classmethod
|
||||
def validate_code(cls, value: str | None):
|
||||
"""
|
||||
校验部门编码:字母开头,仅包含字母/数字/下划线;空字符串视为 None。
|
||||
|
||||
参数:
|
||||
- value (str | None): 部门编码。
|
||||
|
||||
返回:
|
||||
- str | None: 规范化后的部门编码或 None。
|
||||
|
||||
异常:
|
||||
- ValueError: 编码不满足格式要求时抛出。
|
||||
"""
|
||||
if value is None:
|
||||
return value
|
||||
v = value.strip()
|
||||
|
||||
@@ -126,7 +126,7 @@ class DeptService:
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证对象。
|
||||
- ids (List[int]): 部门 ID 列表。
|
||||
- ids (list[int]): 部门 ID 列表。
|
||||
|
||||
返回:
|
||||
- None
|
||||
|
||||
Reference in New Issue
Block a user