Commit 38cc30ce authored by Anton Akhmerov's avatar Anton Akhmerov

Merge branch 'bugfix/exam-deletion' into 'master'

Fix exam deletion bug

Closes #243 and #307

See merge request zesje/zesje!142
parents 7e605ee2 e6c5eec2
Pipeline #17755 passed with stages
in 3 minutes and 11 seconds
......@@ -80,7 +80,9 @@ class Exams extends React.Component {
// This might try to save the name unnecessary, but better twice than never.
this.saveProblemName()
// Force an update of the upper exam state, since this component does not update and use that correctly
this.props.updateExam(this.props.examID)
if (!this.state.deletingExam) {
this.props.updateExam(this.props.examID)
}
}
saveProblemName = () => {
......
......@@ -39,8 +39,26 @@ class Exams(Resource):
return dict(status=404, message='Exam does not exist.'), 404
elif exam.finalized:
return dict(status=409, message='Cannot delete a finalized exam.'), 409
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:
exam.delete()
# 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)
db.session.delete(exam)
db.session.commit()
return dict(status=200, message="ok"), 200
def _get_all(self):
"""get list of uploaded exams.
......
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