文件

43 行
1.8 KiB
Python

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
"""学科配置表:学科=配置而非插件(微核心+插件架构的配置层)。
每个学科挂:提示词(对话机制基座)、LaTeX 速查表键、题库路由、启用状态。
注册页/工作台/教师端共用;管理员可 CRUD。
"""
from __future__ import annotations
from datetime import datetime
from sqlalchemy import DateTime, Integer, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column
from app.core.db import Base
class Course(Base):
__tablename__ = "courses"
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
code: Mapped[str] = mapped_column(String(32), unique=True, index=True) # ap-csa / usaco / ap-calc ...
name: Mapped[str] = mapped_column(String(64)) # AP CSA / USACO ...
# 学科对话机制提示词(基座;学生发散问题仍自由回应,不强拉题目)
prompt: Mapped[str] = mapped_column(Text, default="")
# LaTeX 速查表键(对应 data/latex_sheet.json courses[].id,如 ap-calc)
latex_key: Mapped[str] = mapped_column(String(32), default="common")
# 题库路由:HydroOJ domain 或题目单前缀(留空=全局题单)
problem_route: Mapped[str] = mapped_column(String(64), default="")
enabled: Mapped[bool] = mapped_column(Integer, default=1)
sort: Mapped[int] = mapped_column(Integer, default=100)
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
def to_dict(self) -> dict:
return {
"id": self.id,
"code": self.code,
"name": self.name,
"prompt": self.prompt,
"latex_key": self.latex_key,
"problem_route": self.problem_route,
"enabled": bool(self.enabled),
"sort": self.sort,
}