Files
zkxw/backend/app/core/context.py
T
2026-05-20 14:32:07 +08:00

10 lines
421 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""请求级别的用户上下文变量
通过 contextvars 在请求处理链路中传递当前用户信息,
供 SQLAlchemy 事件监听器等底层机制使用,避免逐层手动传参。
"""
from contextvars import ContextVar
# 当前登录用户的部门 ID(对应 SysUser.dept_id,在 user dict 中键名为 region_id)
current_user_dept_id: ContextVar[str] = ContextVar("current_user_dept_id", default="")