mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 13:05:18 +00:00
本次提交包含多项优化: 1. 移除大量冗余的文件头注释与过时的from __future__导入 2. 将CRUD的list方法统一重命名为get_list保持接口一致 3. 修复前后端状态字段类型不匹配问题,将string类型status改为number 4. 修正前端文案错别字,将"代办事项"修正为标准写法 5. 更新sqlalchemy版本并调整依赖配置 6. 新增缓存工具类替代fastapi-cache2,重构缓存调用逻辑 7. 新增开源授权函生成相关工具与数据库字段支持 8. 为多个业务模块添加防重复提交loading状态 9. 修复邮件模型的外键关联缺失问题 10. 优化pdf生成工具的导入时机与文档注释
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
from contextvars import ContextVar, Token
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
# ── 日志注入 ──
|
|
_correlation_id: ContextVar[str] = ContextVar("correlation_id", default="")
|
|
|
|
|
|
def set_correlation_id(cid: str) -> Token:
|
|
return _correlation_id.set(cid)
|
|
|
|
def get_correlation_id() -> str:
|
|
return _correlation_id.get()
|
|
|
|
def reset_correlation_id(token: Token) -> None:
|
|
_correlation_id.reset(token)
|
|
|
|
|
|
# ── 租户上下文 ──
|
|
current_tenant_id: ContextVar[int | None] = ContextVar("current_tenant_id", default=None)
|
|
|
|
|
|
def set_current_tenant(tenant_id: int | None) -> None:
|
|
current_tenant_id.set(tenant_id)
|
|
|
|
def get_current_tenant_id() -> int | None:
|
|
return current_tenant_id.get()
|
|
|
|
def clear_current_tenant() -> None:
|
|
current_tenant_id.set(None)
|
|
|
|
|
|
# ── request.state.ctx ──
|
|
|
|
@dataclass
|
|
class RequestContext:
|
|
jwt_payload: Any = None
|
|
jwt_user_info: dict[str, Any] | None = None
|
|
session_id: str | None = None
|
|
user_id: int | None = None
|
|
user_username: str | None = None
|
|
session_info: dict[str, Any] | None = None
|
|
login_location: str | None = None
|