Commit 163bb671 authored by Hugo Kerstens's avatar Hugo Kerstens

Use cascades for deletion in the api

parent f075de53
......@@ -42,19 +42,7 @@ class Exams(Resource):
elif Submission.query.filter(Submission.exam_id == exam.id).count():
return dict(status=500, message='Exam is not finalized but already has submissions.'), 500
else:
# Delete any scans that were wrongly uploaded to this exam
for scan in exam.scans:
db.session.delete(scan)
for widget in exam.widgets:
db.session.delete(widget)
for problem in exam.problems:
for fb_option in problem.feedback_options:
db.session.delete(fb_option)
db.session.delete(problem.widget)
db.session.delete(problem)
# All corresponding solutions, scans and problems are automatically deleted
db.session.delete(exam)
db.session.commit()
......
......@@ -105,10 +105,7 @@ class Problems(Resource):
if any([sol.graded_by is not None for sol in problem.solutions]):
return dict(status=403, message=f'Problem has already been graded'), 403
else:
# Delete all solutions associated with this problem
for sol in problem.solutions:
db.session.delete(sol)
db.session.delete(problem.widget)
# The widget and all associated solutions are automatically deleted
db.session.delete(problem)
db.session.commit()
return dict(status=200, message="ok"), 200
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment