mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 04:46:26 +00:00
style: 优化代码格式和导入顺序
refactor: 重构数据库连接模块,提高可维护性 docs: 更新README.md项目描述 style: 调整日志输出格式和内容 refactor: 优化中间件日志记录逻辑 style: 统一代码中的空行和导入顺序 refactor: 分离数据库引擎和会话创建逻辑 style: 清理未使用的导入和代码 refactor: 重命名数据库会话变量 style: 调整jinja2模板变量命名 refactor: 优化异常处理和日志记录 style: 统一字符串格式化方式 refactor: 优化redis连接错误处理 style: 调整注释格式和位置 refactor: 优化数据库连接配置 style: 清理多余空行和注释
This commit is contained in:
@@ -17,6 +17,7 @@ from app.core.dependencies import (
|
||||
get_current_user,
|
||||
redis_getter
|
||||
)
|
||||
|
||||
from .service import (
|
||||
LoginService,
|
||||
CaptchaService
|
||||
|
||||
@@ -14,15 +14,16 @@ from app.utils.common_util import get_random_character
|
||||
from app.utils.captcha_util import CaptchaUtil
|
||||
from app.utils.ip_local_util import IpLocalUtil
|
||||
from app.utils.hash_bcrpy_util import PwdUtil
|
||||
from app.core.redis_crud import RedisCURD
|
||||
from app.core.exceptions import CustomException
|
||||
from app.core.logger import logger
|
||||
from app.config.setting import settings
|
||||
from app.core.security import (
|
||||
CustomOAuth2PasswordRequestForm,
|
||||
create_access_token,
|
||||
decode_access_token
|
||||
)
|
||||
from app.core.redis_crud import RedisCURD
|
||||
from app.core.exceptions import CustomException
|
||||
from app.core.logger import logger
|
||||
from app.config.setting import settings
|
||||
|
||||
from app.api.v1.module_monitor.online.schema import OnlineOutSchema
|
||||
from ..user.crud import UserCRUD
|
||||
from ..user.model import UserModel
|
||||
|
||||
@@ -8,6 +8,7 @@ from app.core.router_class import OperationLogRoute
|
||||
from app.core.dependencies import AuthPermission
|
||||
from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.logger import logger
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .param import DeptQueryParam
|
||||
from .service import DeptService
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from typing import Dict, List, Optional, Sequence, Union, Any
|
||||
|
||||
from app.core.base_crud import CRUDBase
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .model import DeptModel
|
||||
from .schema import DeptCreateSchema, DeptUpdateSchema
|
||||
|
||||
@@ -5,6 +5,7 @@ from fastapi import Query
|
||||
|
||||
from app.core.validator import DateTimeStr
|
||||
|
||||
|
||||
class DeptQueryParam:
|
||||
"""部门管理查询参数"""
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ from app.utils.common_util import (
|
||||
get_child_recursion,
|
||||
traversal_to_tree
|
||||
)
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .crud import DeptCRUD
|
||||
from .param import DeptQueryParam
|
||||
|
||||
@@ -13,6 +13,7 @@ from app.core.router_class import OperationLogRoute
|
||||
from app.core.logger import logger
|
||||
from app.common.request import PaginationService
|
||||
from app.utils.common_util import bytes2file_response
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .param import DictTypeQueryParam, DictDataQueryParam
|
||||
from .service import DictTypeService, DictDataService
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from typing import Dict, List, Optional, Sequence, Union, Any
|
||||
|
||||
from app.core.base_crud import CRUDBase
|
||||
|
||||
from app.api.v1.module_system.dict.model import DictDataModel, DictTypeModel
|
||||
from app.api.v1.module_system.dict.schema import DictDataCreateSchema, DictDataUpdateSchema, DictTypeCreateSchema, DictTypeUpdateSchema
|
||||
from app.api.v1.module_system.auth.schema import AuthSchema
|
||||
|
||||
@@ -6,11 +6,12 @@ from redis.asyncio.client import Redis
|
||||
|
||||
from app.common.enums import RedisInitKeyConfig
|
||||
from app.utils.excel_util import ExcelUtil
|
||||
from app.core.database import AsyncSessionLocal
|
||||
from app.core.database import async_db_session
|
||||
from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.redis_crud import RedisCURD
|
||||
from app.core.exceptions import CustomException
|
||||
from app.core.logger import logger
|
||||
|
||||
from app.api.v1.module_system.auth.schema import AuthSchema
|
||||
from .schema import DictDataCreateSchema,DictDataOutSchema,DictDataUpdateSchema,DictTypeCreateSchema,DictTypeOutSchema,DictTypeUpdateSchema
|
||||
from .param import DictDataQueryParam, DictTypeQueryParam
|
||||
@@ -280,7 +281,7 @@ class DictDataService:
|
||||
返回:
|
||||
- None
|
||||
"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
async with async_db_session() as session:
|
||||
async with session.begin():
|
||||
auth = AuthSchema(db=session)
|
||||
obj_list = await DictTypeCRUD(auth).get_obj_list_crud()
|
||||
|
||||
@@ -10,6 +10,7 @@ from app.core.router_class import OperationLogRoute
|
||||
from app.core.dependencies import AuthPermission
|
||||
from app.core.base_params import PaginationQueryParam
|
||||
from app.core.logger import logger
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .param import OperationLogQueryParam
|
||||
from .service import OperationLogService
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from typing import Dict, List, Optional, Sequence, Union, Any
|
||||
|
||||
from app.core.base_crud import CRUDBase
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .model import OperationLogModel
|
||||
from .schema import OperationLogCreateSchema
|
||||
|
||||
@@ -5,6 +5,7 @@ from fastapi import Query
|
||||
|
||||
from app.core.validator import DateTimeStr
|
||||
|
||||
|
||||
class OperationLogQueryParam:
|
||||
"""操作日志查询参数"""
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import re
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
||||
|
||||
from app.core.base_schema import BaseSchema
|
||||
import re
|
||||
|
||||
|
||||
class OperationLogCreateSchema(BaseModel):
|
||||
|
||||
@@ -4,6 +4,7 @@ from typing import Any, Dict, List, Optional
|
||||
|
||||
from app.core.exceptions import CustomException
|
||||
from app.utils.excel_util import ExcelUtil
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .param import OperationLogQueryParam
|
||||
from .crud import OperationLogCRUD
|
||||
|
||||
@@ -8,6 +8,7 @@ from app.core.dependencies import AuthPermission
|
||||
from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.router_class import OperationLogRoute
|
||||
from app.core.logger import logger
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .param import MenuQueryParam
|
||||
from .service import MenuService
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from typing import Dict, List, Optional, Sequence, Union, Any
|
||||
|
||||
from app.core.base_crud import CRUDBase
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .model import MenuModel
|
||||
from .schema import MenuCreateSchema, MenuUpdateSchema
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
"""
|
||||
|
||||
from typing import Optional, List, TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import Boolean, String, Integer, JSON, ForeignKey
|
||||
from sqlalchemy.orm import relationship, Mapped, mapped_column
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from fastapi import Query
|
||||
|
||||
from app.core.validator import DateTimeStr
|
||||
|
||||
|
||||
class MenuQueryParam:
|
||||
"""菜单管理查询参数"""
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ from app.utils.common_util import (
|
||||
get_child_recursion,
|
||||
traversal_to_tree
|
||||
)
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .param import MenuQueryParam
|
||||
from .crud import MenuCRUD
|
||||
|
||||
@@ -11,6 +11,7 @@ from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.logger import logger
|
||||
from app.common.request import PaginationService
|
||||
from app.utils.common_util import bytes2file_response
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .param import NoticeQueryParam
|
||||
from .service import NoticeService
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from typing import Dict, List, Optional, Sequence, Union, Any
|
||||
|
||||
from app.core.base_crud import CRUDBase
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .model import NoticeModel
|
||||
from .schema import NoticeCreateSchema, NoticeUpdateSchema
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import Boolean, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from typing import Any, List, Dict, Optional
|
||||
from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.exceptions import CustomException
|
||||
from app.utils.excel_util import ExcelUtil
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .schema import NoticeCreateSchema, NoticeUpdateSchema, NoticeOutSchema
|
||||
from .param import NoticeQueryParam
|
||||
|
||||
@@ -4,7 +4,6 @@ from fastapi import APIRouter, Body, Depends, Path, Query, Request, UploadFile
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
from redis.asyncio.client import Redis
|
||||
|
||||
|
||||
from app.common.request import PaginationService
|
||||
from app.common.response import StreamResponse, SuccessResponse
|
||||
from app.utils.common_util import bytes2file_response
|
||||
@@ -12,6 +11,7 @@ from app.core.base_params import PaginationQueryParam
|
||||
from app.core.dependencies import AuthPermission, redis_getter
|
||||
from app.core.router_class import OperationLogRoute
|
||||
from app.core.logger import logger
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .param import ParamsQueryParam
|
||||
from .schema import ParamsCreateSchema, ParamsUpdateSchema
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from typing import Dict, List, Optional, Sequence, Union, Any
|
||||
|
||||
from app.core.base_crud import CRUDBase
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .model import ParamsModel
|
||||
from .schema import ParamsCreateSchema, ParamsUpdateSchema
|
||||
|
||||
@@ -5,6 +5,7 @@ from fastapi import Query
|
||||
|
||||
from app.core.validator import DateTimeStr
|
||||
|
||||
|
||||
class ParamsQueryParam:
|
||||
"""配置管理查询参数"""
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@ from fastapi import UploadFile
|
||||
from redis.asyncio.client import Redis
|
||||
|
||||
from app.common.enums import RedisInitKeyConfig
|
||||
from app.core.database import AsyncSessionLocal
|
||||
from app.core.database import async_db_session
|
||||
from app.core.redis_crud import RedisCURD
|
||||
from app.utils.excel_util import ExcelUtil
|
||||
from app.utils.upload_util import UploadUtil
|
||||
from app.core.base_schema import UploadResponseSchema
|
||||
from app.core.exceptions import CustomException
|
||||
from app.core.logger import logger
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .param import ParamsQueryParam
|
||||
from .schema import ParamsOutSchema, ParamsUpdateSchema, ParamsCreateSchema
|
||||
@@ -276,7 +277,7 @@ class ParamsService:
|
||||
返回:
|
||||
- None
|
||||
"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
async with async_db_session() as session:
|
||||
async with session.begin():
|
||||
auth = AuthSchema(db=session)
|
||||
config_obj = await ParamsCRUD(auth).get_obj_list_crud()
|
||||
|
||||
@@ -11,6 +11,7 @@ from app.core.router_class import OperationLogRoute
|
||||
from app.core.dependencies import AuthPermission
|
||||
from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.logger import logger
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .service import PositionService
|
||||
from .param import PositionQueryParam
|
||||
|
||||
@@ -5,6 +5,7 @@ from fastapi import Query
|
||||
|
||||
from app.core.validator import DateTimeStr
|
||||
|
||||
|
||||
class PositionQueryParam:
|
||||
"""岗位管理查询参数"""
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Optional
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||
|
||||
from app.core.base_schema import BaseSchema
|
||||
from app.core.validator import DateTimeStr
|
||||
|
||||
|
||||
class PositionCreateSchema(BaseModel):
|
||||
"""岗位创建模型"""
|
||||
|
||||
@@ -5,6 +5,7 @@ from typing import Any, Dict, List, Optional
|
||||
from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.exceptions import CustomException
|
||||
from app.utils.excel_util import ExcelUtil
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .param import PositionQueryParam
|
||||
from .crud import PositionCRUD
|
||||
|
||||
@@ -11,6 +11,7 @@ from app.core.base_params import PaginationQueryParam
|
||||
from app.core.dependencies import AuthPermission
|
||||
from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.logger import logger
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .service import RoleService
|
||||
from .param import RoleQueryParam
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from typing import Dict, List, Sequence, Optional, Union, Any
|
||||
|
||||
from app.core.base_crud import CRUDBase
|
||||
|
||||
from .model import RoleModel
|
||||
from .schema import RoleCreateSchema, RoleUpdateSchema
|
||||
from ..auth.schema import AuthSchema
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
"""
|
||||
|
||||
from typing import Optional, List, TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import Boolean, String, Integer, ForeignKey
|
||||
from sqlalchemy.orm import relationship, Mapped, mapped_column
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from fastapi import Query
|
||||
|
||||
from app.core.validator import DateTimeStr
|
||||
|
||||
|
||||
class RoleQueryParam:
|
||||
"""角色管理查询参数"""
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from pydantic import BaseModel, ConfigDict, Field, model_validator, field_valida
|
||||
from app.core.base_schema import BaseSchema
|
||||
from app.core.validator import role_permission_request_validator
|
||||
from app.core.validator import DateTimeStr
|
||||
|
||||
from ..dept.schema import DeptOutSchema
|
||||
from ..menu.schema import MenuOutSchema
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from typing import Any, Dict, List, Optional
|
||||
from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.exceptions import CustomException
|
||||
from app.utils.excel_util import ExcelUtil
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .crud import RoleCRUD
|
||||
from .param import RoleQueryParam
|
||||
|
||||
@@ -11,6 +11,7 @@ from app.core.dependencies import AuthPermission
|
||||
from app.core.router_class import OperationLogRoute
|
||||
from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.logger import logger
|
||||
|
||||
from app.api.v1.module_system.auth.schema import AuthSchema
|
||||
from .param import TenantQueryParam
|
||||
from .service import TenantService
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from typing import Dict, List, Optional, Sequence, Union, Any
|
||||
|
||||
from app.core.base_crud import CRUDBase
|
||||
|
||||
from app.api.v1.module_system.auth.schema import AuthSchema
|
||||
from .model import TenantModel
|
||||
from .schema import TenantCreateSchema, TenantUpdateSchema, TenantOutSchema
|
||||
|
||||
@@ -5,6 +5,7 @@ from fastapi import Query
|
||||
|
||||
from app.core.validator import DateTimeStr
|
||||
|
||||
|
||||
class TenantQueryParam:
|
||||
"""租户查询参数"""
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.exceptions import CustomException
|
||||
from app.utils.excel_util import ExcelUtil
|
||||
from app.core.logger import logger
|
||||
|
||||
from app.api.v1.module_system.auth.schema import AuthSchema
|
||||
from .schema import TenantCreateSchema, TenantUpdateSchema, TenantOutSchema
|
||||
from .param import TenantQueryParam
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import urllib.parse
|
||||
from fastapi import APIRouter, Depends, Body, Path, Query, Form, File, UploadFile, Request
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
import urllib.parse
|
||||
|
||||
from app.common.response import StreamResponse, SuccessResponse
|
||||
from app.common.request import PaginationService
|
||||
@@ -13,6 +13,7 @@ from app.core.dependencies import db_getter, get_current_user, AuthPermission
|
||||
from app.core.base_params import PaginationQueryParam
|
||||
from app.core.base_schema import BatchSetAvailable
|
||||
from app.core.logger import logger
|
||||
|
||||
from ..auth.schema import AuthSchema
|
||||
from .service import UserService
|
||||
from .param import UserQueryParam
|
||||
|
||||
@@ -4,13 +4,13 @@ from typing import Dict, List, Optional, Sequence, Union, Any
|
||||
from datetime import datetime
|
||||
|
||||
from app.core.base_crud import CRUDBase
|
||||
|
||||
from app.api.v1.module_system.auth.schema import AuthSchema
|
||||
from .model import UserModel
|
||||
from .schema import UserCreateSchema, UserForgetPasswordSchema, UserUpdateSchema
|
||||
from ..role.crud import RoleCRUD
|
||||
from ..position.crud import PositionCRUD
|
||||
|
||||
from app.api.v1.module_system.auth.schema import AuthSchema
|
||||
|
||||
|
||||
class UserCRUD(CRUDBase[UserModel, UserCreateSchema, UserUpdateSchema]):
|
||||
"""用户模块数据层"""
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Optional, List
|
||||
|
||||
from sqlalchemy import Boolean, String, Integer, DateTime, ForeignKey, Text
|
||||
from sqlalchemy.orm import relationship, Mapped, mapped_column
|
||||
|
||||
from app.core.base_model import MappedBase
|
||||
|
||||
from app.api.v1.module_system.dept.model import DeptModel
|
||||
from app.api.v1.module_system.position.model import PositionModel
|
||||
from app.api.v1.module_system.role.model import RoleModel
|
||||
from app.core.base_model import MappedBase
|
||||
|
||||
|
||||
class UserRolesModel(MappedBase):
|
||||
|
||||
@@ -5,6 +5,7 @@ from fastapi import Query
|
||||
|
||||
from app.core.validator import DateTimeStr
|
||||
|
||||
|
||||
class UserQueryParam:
|
||||
"""用户管理查询参数"""
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
from typing import Optional, List
|
||||
from pydantic import BaseModel, ConfigDict, Field, EmailStr, field_validator
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from app.core.validator import DateTimeStr, mobile_validator
|
||||
from app.core.base_schema import BaseSchema, CommonSchema
|
||||
|
||||
from app.api.v1.module_system.role.schema import RoleOutSchema
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
class CurrentUserUpdateSchema(BaseModel):
|
||||
"""基础用户信息"""
|
||||
|
||||
@@ -12,6 +12,7 @@ from app.core.logger import logger
|
||||
from app.utils.common_util import traversal_to_tree
|
||||
from app.utils.excel_util import ExcelUtil
|
||||
from app.utils.upload_util import UploadUtil
|
||||
|
||||
from ..position.crud import PositionCRUD
|
||||
from ..role.crud import RoleCRUD
|
||||
from ..menu.crud import MenuCRUD
|
||||
|
||||
Reference in New Issue
Block a user