更新:models/routes/services/templates/docs
This commit is contained in:
+2
-10
@@ -18,23 +18,15 @@ def get_student_problems(student_id):
|
||||
@main_bp.route("/api/students/<int:student_id>/problems", methods=["POST"])
|
||||
@login_required_json
|
||||
def add_student_problem(student_id):
|
||||
"""为学员添加问题(同步模式:先删再加)"""
|
||||
"""为学员添加问题(增量模式:只添加或更新,不删除已有)"""
|
||||
student = Student.query.get_or_404(student_id)
|
||||
data = request.get_json()
|
||||
|
||||
problems = data.get("problems", [])
|
||||
submitted_ids = set()
|
||||
|
||||
# 删除旧的问题(如果勾选被取消)
|
||||
existing = StudentProblem.query.filter_by(student_id=student_id).all()
|
||||
for e in existing:
|
||||
if e.problem_id not in [p.get("problem_id") for p in problems]:
|
||||
db.session.delete(e)
|
||||
|
||||
# 添加或更新问题
|
||||
# 添加或更新问题(不删除已有的)
|
||||
for p in problems:
|
||||
problem_id = p.get("problem_id") # 这是 problems.id
|
||||
submitted_ids.add(problem_id)
|
||||
|
||||
# 检查是否已存在
|
||||
existing = StudentProblem.query.filter_by(
|
||||
|
||||
Reference in New Issue
Block a user