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
This commit is contained in:
Wu Clan
2025-10-10 19:02:49 +08:00
committed by GitHub
parent 51354593d0
commit 5762834744
269 changed files with 975 additions and 1198 deletions
-2
View File
@@ -1,2 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-2
View File
@@ -1,2 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-2
View File
@@ -1,2 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
@@ -1,2 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
+7 -4
View File
@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Annotated
from fastapi import APIRouter, Depends, Path, Query
@@ -60,7 +58,11 @@ async def get_dict_datas_paged(
type_id: Annotated[int | None, Query(description='字典类型 ID')] = None,
) -> ResponseSchemaModel[PageData[GetDictDataDetail]]:
dict_data_select = await dict_data_service.get_select(
type_code=type_code, label=label, value=value, status=status, type_id=type_id
type_code=type_code,
label=label,
value=value,
status=status,
type_id=type_id,
)
page_data = await paging_data(db, dict_data_select)
return response_base.success(data=page_data)
@@ -88,7 +90,8 @@ async def create_dict_data(obj: CreateDictDataParam) -> ResponseModel:
],
)
async def update_dict_data(
pk: Annotated[int, Path(description='字典数据 ID')], obj: UpdateDictDataParam
pk: Annotated[int, Path(description='字典数据 ID')],
obj: UpdateDictDataParam,
) -> ResponseModel:
count = await dict_data_service.update(pk=pk, obj=obj)
if count > 0:
+2 -3
View File
@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Annotated
from fastapi import APIRouter, Depends, Path, Query
@@ -75,7 +73,8 @@ async def create_dict_type(obj: CreateDictTypeParam) -> ResponseModel:
],
)
async def update_dict_type(
pk: Annotated[int, Path(description='字典类型 ID')], obj: UpdateDictTypeParam
pk: Annotated[int, Path(description='字典类型 ID')],
obj: UpdateDictTypeParam,
) -> ResponseModel:
count = await dict_type_service.update(pk=pk, obj=obj)
if count > 0:
-2
View File
@@ -1,2 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
+12 -5
View File
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Sequence
from collections.abc import Sequence
from sqlalchemy import Select
from sqlalchemy.ext.asyncio import AsyncSession
@@ -32,7 +30,11 @@ class CRUDDictData(CRUDPlus[DictData]):
:return:
"""
return await self.select_models_order(
db, sort_columns='sort', sort_orders='desc', type_code=type_code, load_strategies={'type': 'noload'}
db,
sort_columns='sort',
sort_orders='desc',
type_code=type_code,
load_strategies={'type': 'noload'},
)
async def get_all(self, db: AsyncSession) -> Sequence[DictData]:
@@ -45,7 +47,12 @@ class CRUDDictData(CRUDPlus[DictData]):
return await self.select_models(db, load_strategies={'type': 'noload'})
async def get_list(
self, type_code: str | None, label: str | None, value: str | None, status: int | None, type_id: int | None
self,
type_code: str | None,
label: str | None,
value: str | None,
status: int | None,
type_id: int | None,
) -> Select:
"""
获取字典数据列表
+1 -3
View File
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Sequence
from collections.abc import Sequence
from sqlalchemy import Select
from sqlalchemy.ext.asyncio import AsyncSession
+2 -4
View File
@@ -1,4 +1,2 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from backend.plugin.dict.model.dict_data import DictData
from backend.plugin.dict.model.dict_type import DictType
from backend.plugin.dict.model.dict_data import DictData as DictData
from backend.plugin.dict.model.dict_type import DictType as DictType
+6 -4
View File
@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations
from typing import TYPE_CHECKING
@@ -28,11 +26,15 @@ class DictData(Base):
sort: Mapped[int] = mapped_column(default=0, comment='排序')
status: Mapped[int] = mapped_column(default=1, comment='状态(0停用 1正常)')
remark: Mapped[str | None] = mapped_column(
LONGTEXT().with_variant(TEXT, 'postgresql'), default=None, comment='备注'
LONGTEXT().with_variant(TEXT, 'postgresql'),
default=None,
comment='备注',
)
# 字典类型一对多
type_id: Mapped[int] = mapped_column(
ForeignKey('sys_dict_type.id', ondelete='CASCADE'), default=0, comment='字典类型关联ID'
ForeignKey('sys_dict_type.id', ondelete='CASCADE'),
default=0,
comment='字典类型关联ID',
)
type: Mapped[DictType] = relationship(init=False, back_populates='datas')
+3 -3
View File
@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations
from typing import TYPE_CHECKING
@@ -24,7 +22,9 @@ class DictType(Base):
name: Mapped[str] = mapped_column(String(32), comment='字典类型名称')
code: Mapped[str] = mapped_column(String(32), unique=True, comment='字典类型编码')
remark: Mapped[str | None] = mapped_column(
LONGTEXT().with_variant(TEXT, 'postgresql'), default=None, comment='备注'
LONGTEXT().with_variant(TEXT, 'postgresql'),
default=None,
comment='备注',
)
# 字典类型一对多
-2
View File
@@ -1,2 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-2
View File
@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from datetime import datetime
from pydantic import ConfigDict, Field
-2
View File
@@ -1,5 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from datetime import datetime
from pydantic import ConfigDict, Field
-2
View File
@@ -1,2 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Sequence
from collections.abc import Sequence
from sqlalchemy import Select
@@ -51,7 +49,12 @@ class DictDataService:
@staticmethod
async def get_select(
*, type_code: str | None, label: str | None, value: str | None, status: int | None, type_id: int | None
*,
type_code: str | None,
label: str | None,
value: str | None,
status: int | None,
type_id: int | None,
) -> Select:
"""
获取字典数据列表查询条件
@@ -64,7 +67,11 @@ class DictDataService:
:return:
"""
return await dict_data_dao.get_list(
type_code=type_code, label=label, value=value, status=status, type_id=type_id
type_code=type_code,
label=label,
value=value,
status=status,
type_id=type_id,
)
@staticmethod
@@ -97,9 +104,8 @@ class DictDataService:
dict_data = await dict_data_dao.get(db, pk)
if not dict_data:
raise errors.NotFoundError(msg='字典数据不存在')
if dict_data.label != obj.label:
if await dict_data_dao.get_by_label(db, obj.label):
raise errors.ConflictError(msg='字典数据已存在')
if dict_data.label != obj.label and await dict_data_dao.get_by_label(db, obj.label):
raise errors.ConflictError(msg='字典数据已存在')
dict_type = await dict_type_dao.get(db, obj.type_id)
if not dict_type:
raise errors.NotFoundError(msg='字典类型不存在')
@@ -1,6 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Sequence
from collections.abc import Sequence
from sqlalchemy import Select
@@ -15,7 +13,7 @@ class DictTypeService:
"""字典类型服务类"""
@staticmethod
async def get(*, pk) -> DictType:
async def get(*, pk: int) -> DictType:
"""
获取字典类型详情
@@ -72,9 +70,8 @@ class DictTypeService:
dict_type = await dict_type_dao.get(db, pk)
if not dict_type:
raise errors.NotFoundError(msg='字典类型不存在')
if dict_type.code != obj.code:
if await dict_type_dao.get_by_code(db, obj.code):
raise errors.ConflictError(msg='字典类型已存在')
if dict_type.code != obj.code and await dict_type_dao.get_by_code(db, obj.code):
raise errors.ConflictError(msg='字典类型已存在')
count = await dict_type_dao.update(db, pk, obj)
return count