feat: 问题数据迁移到数据库;学员详情页URL导航改造;侧边栏统一
- 问题从文件系统迁移到数据库 problems 表 - 移除 PROBLEMS_DIR 配置和文件读取逻辑 - student.html 完整重写:编辑/添加/删除问题,生成方案进度显示 - 学员详情页支持独立URL访问 (/student/<id>) - 统一侧边栏到 base.html - 更新文档:DEPLOYMENT_SOP, MODELS, STRUCTURE, FRONTEND_ARCH - 部署到生产环境 v1.2.0
This commit is contained in:
+17
-10
@@ -25,14 +25,6 @@ def create_app():
|
||||
)
|
||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||
|
||||
# 问题文件目录
|
||||
is_docker = os.environ.get("FLASK_ENV") == "production"
|
||||
if is_docker:
|
||||
app.config["PROBLEMS_DIR"] = BASE_DIR / "个性化方案"
|
||||
else:
|
||||
# 本地开发:问题文件在父目录的 个性化方案/针对性练习(拆分为单独文件)
|
||||
app.config["PROBLEMS_DIR"] = BASE_DIR.parent / "个性化方案" / "针对性练习(拆分为单独文件)"
|
||||
|
||||
app.config["PDF_OUTPUT_DIR"] = BASE_DIR / "output"
|
||||
app.config["API_CONFIG_FILE"] = BASE_DIR / "config" / "api_config.json"
|
||||
|
||||
@@ -109,11 +101,26 @@ def create_app():
|
||||
if "sort_order" not in template_columns:
|
||||
db.session.execute(text("ALTER TABLE templates ADD COLUMN sort_order INTEGER DEFAULT 0"))
|
||||
db.session.commit()
|
||||
|
||||
# 检查practice_plans表是否有template_id字段
|
||||
result5 = db.session.execute(text("PRAGMA table_info(practice_plans)"))
|
||||
plan_columns = [row[1] for row in result5]
|
||||
if "template_id" not in plan_columns:
|
||||
db.session.execute(text("ALTER TABLE practice_plans ADD COLUMN template_id INTEGER REFERENCES templates(id)"))
|
||||
db.session.commit()
|
||||
|
||||
# 检查practice_plans表是否有is_typical字段
|
||||
result6 = db.session.execute(text("PRAGMA table_info(practice_plans)"))
|
||||
plan_columns2 = [row[1] for row in result6]
|
||||
if "is_typical" not in plan_columns2:
|
||||
db.session.execute(text("ALTER TABLE practice_plans ADD COLUMN is_typical INTEGER DEFAULT 0"))
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
print(f"数据库迁移: {e}")
|
||||
|
||||
# 初始化默认模板(必须在迁移之后)
|
||||
from app.routes.templates import init_default_templates
|
||||
init_default_templates()
|
||||
# 已禁用:如果需要默认模板,请手动创建
|
||||
# from app.routes.templates import init_default_templates
|
||||
# init_default_templates()
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user