代码提交
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
"""全局枚举与文案映射。
|
||||
|
||||
数据库里一律存 int 代号(省得 MySQL ENUM 改起来要 ALTER),
|
||||
对外出参把代号 + 中文文案一起给出去,前端不用再维护一份映射表。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum, IntEnum
|
||||
|
||||
|
||||
class Gender(IntEnum):
|
||||
MALE = 1
|
||||
FEMALE = 2
|
||||
|
||||
|
||||
GENDER_TEXT: dict[int, str] = {Gender.MALE: "男", Gender.FEMALE: "女"}
|
||||
|
||||
|
||||
class StudentStatus(IntEnum):
|
||||
STUDYING = 1 # 在读
|
||||
EMPLOYING = 2 # 进入就业(已开放就业,还没拿到 offer)
|
||||
EMPLOYED = 3 # 已就业(已下发 offer)
|
||||
|
||||
|
||||
STUDENT_STATUS_TEXT: dict[int, str] = {
|
||||
StudentStatus.STUDYING: "在读",
|
||||
StudentStatus.EMPLOYING: "进入就业",
|
||||
StudentStatus.EMPLOYED: "已就业",
|
||||
}
|
||||
|
||||
|
||||
class ClassStatus(IntEnum):
|
||||
RUNNING = 1 # 在读
|
||||
GRADUATED = 2 # 已结课
|
||||
DISBANDED = 3 # 已解散
|
||||
|
||||
|
||||
CLASS_STATUS_TEXT: dict[int, str] = {
|
||||
ClassStatus.RUNNING: "在读",
|
||||
ClassStatus.GRADUATED: "已结课",
|
||||
ClassStatus.DISBANDED: "已解散",
|
||||
}
|
||||
|
||||
|
||||
class ScoreFlag(IntEnum):
|
||||
NORMAL = 0 # 正常
|
||||
WARNING = 1 # 低于红线,需重点关注
|
||||
|
||||
|
||||
class Education(str, Enum):
|
||||
"""学历(自由文本也用这几个做下拉默认值)。"""
|
||||
|
||||
JUNIOR = "初中"
|
||||
SENIOR = "高中"
|
||||
TECHNICAL = "中专"
|
||||
COLLEGE = "大专"
|
||||
BACHELOR = "本科"
|
||||
MASTER = "硕士"
|
||||
|
||||
|
||||
class Role(str, Enum):
|
||||
ADMIN = "admin" # 教务管理员:全部权限
|
||||
ADVISOR = "advisor" # 顾问:日常录入
|
||||
VIEWER = "viewer" # 只读
|
||||
|
||||
|
||||
ROLE_TEXT: dict[str, str] = {
|
||||
Role.ADMIN: "管理员",
|
||||
Role.ADVISOR: "顾问",
|
||||
Role.VIEWER: "只读访客",
|
||||
}
|
||||
|
||||
|
||||
def gender_to_code(value: int | str | None) -> int | None:
|
||||
"""把 "男"/"女"/1/2 统一转成代号,供查询参数使用。"""
|
||||
if value in (None, ""):
|
||||
return None
|
||||
if isinstance(value, int):
|
||||
return value if value in (1, 2) else None
|
||||
text = str(value).strip()
|
||||
if text in ("男", "M", "m", "male", "Male"):
|
||||
return int(Gender.MALE)
|
||||
if text in ("女", "F", "f", "female", "Female"):
|
||||
return int(Gender.FEMALE)
|
||||
if text.isdigit():
|
||||
return int(text)
|
||||
return None
|
||||
|
||||
|
||||
def gender_to_text(value: int | None) -> str | None:
|
||||
return GENDER_TEXT.get(value) if value is not None else None
|
||||
Reference in New Issue
Block a user