mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 13:05:18 +00:00
这是一次综合性的重构更新,包含以下主要变更: 1. 升级Python版本到3.12,更新依赖配置 2. 替换旧的.j2模板为.jinja2格式,新增代码生成模板 3. 重构权限过滤策略,更新权限枚举与模型配置 4. 移除Prefect依赖,替换为自研拓扑并行执行引擎 5. 重构认证与上下文管理,拆分租户/请求上下文 6. 简化响应模型、CRUD与服务层代码 7. 清理废弃的支付网关模块,重构订单定时任务 8. 更新在线用户、监控等模块的接口与路由 9. 优化邮件模板与工具类,新增邮件模板文件 10. 修复数据库会话配置与类型提示
88 lines
3.8 KiB
Django/Jinja
88 lines
3.8 KiB
Django/Jinja
# -*- coding: utf-8 -*-
|
|
|
|
{% if table.sub %}
|
|
from typing import List
|
|
{% endif %}
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
from fastapi import Query
|
|
{% for import_stmt in schema_import_list %}
|
|
{{ import_stmt }}
|
|
{% endfor %}
|
|
{# DateTimeStr 由 schema_import_list 在存在 created_time/updated_time 列时注入 #}
|
|
from app.common.enums import QueueEnum
|
|
from app.core.base_schema import BaseSchema, UserBySchema
|
|
|
|
class {{ class_name }}CreateSchema(BaseModel):
|
|
"""
|
|
{{ function_name }}新增模型
|
|
"""
|
|
{% for column in columns %}
|
|
{% if column.column_name not in ['uuid', 'created_time', 'updated_time', 'created_id', 'updated_id', 'is_deleted', 'deleted_time', 'deleted_id'] and column.column_name != pk_column_name %}
|
|
{% if column.column_name == 'status' %}
|
|
{{ column.column_name }}: {{ column.python_type }} = Field(default="0", description='{{ column.column_comment }}')
|
|
{% elif column.column_name == 'description' %}
|
|
{{ column.column_name }}: str | None = Field(default=None, max_length=255, description='{{ column.column_comment }}')
|
|
{% else %}
|
|
{{ column.column_name }}: {{ column.python_type }} = Field(default=..., description='{{ column.column_comment }}')
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
|
|
class {{ class_name }}UpdateSchema({{ class_name }}CreateSchema):
|
|
"""
|
|
{{ function_name }}更新模型
|
|
"""
|
|
...
|
|
|
|
|
|
class {{ class_name }}OutSchema({{ class_name }}CreateSchema, BaseSchema, UserBySchema):
|
|
"""
|
|
{{ function_name }}响应模型
|
|
"""
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class {{ class_name }}QueryParam:
|
|
"""{{ function_name }}查询参数"""
|
|
|
|
def __init__(
|
|
self,
|
|
{% for column in columns %}
|
|
{% if column.is_query and column.query_type == 'LIKE' %}
|
|
{{ column.column_name }}: str | None = Query(None, description="{{ column.column_comment }}"),
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% for column in columns %}
|
|
{% if column.is_query and column.query_type == 'EQ' and column.column_name not in ['created_time', 'updated_time'] %}
|
|
{{ column.column_name }}: {{ column.python_type }} | None = Query(None, description="{{ column.column_comment }}"),
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% if 'created_time' in table_column_names %}
|
|
created_time: list[DateTimeStr] | None = Query(None, description="创建时间范围", examples=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
|
|
{% endif %}
|
|
{% if 'updated_time' in table_column_names %}
|
|
updated_time: list[DateTimeStr] | None = Query(None, description="更新时间范围", examples=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
|
|
{% endif %}
|
|
) -> None:
|
|
{% for column in columns %}
|
|
{% if column.is_query and column.query_type == 'LIKE' %}
|
|
# 模糊查询字段
|
|
self.{{ column.column_name }} = (QueueEnum.like.value, {{ column.column_name }})
|
|
{% elif column.is_query and column.query_type == 'EQ' and column.column_name not in ['created_time', 'updated_time'] %}
|
|
# 精确查询字段
|
|
if {{ column.column_name }} is not None:
|
|
self.{{ column.column_name }} = (QueueEnum.eq.value, {{ column.column_name }})
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% if 'created_time' in table_column_names %}
|
|
# 时间范围查询
|
|
if created_time and len(created_time) == 2:
|
|
self.created_time = (QueueEnum.between.value, (created_time[0], created_time[1]))
|
|
{% endif %}
|
|
{% if 'updated_time' in table_column_names %}
|
|
if updated_time and len(updated_time) == 2:
|
|
self.updated_time = (QueueEnum.between.value, (updated_time[0], updated_time[1]))
|
|
{% endif %}
|
|
{# created_id / updated_id 若为 EQ 查询列,已在上方 query_type 循环中处理 #}
|