From bc13bdce80c7a0b98c9aaf204b9f2260ede9bd4c Mon Sep 17 00:00:00 2001 From: James Wang Date: Sun, 17 Apr 2016 09:27:46 -0400 Subject: [PATCH] Add support for custom responses in the grader --- server/api/problem.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/server/api/problem.py b/server/api/problem.py index d1d0f6b..821e68f 100644 --- a/server/api/problem.py +++ b/server/api/problem.py @@ -128,22 +128,22 @@ def problem_submit(): solved = Solves.query.filter_by(pid=pid, tid=tid, correct=1).first() if solved: raise WebException("You already solved this problem.") - if problem: - grader = imp.load_source("grader.py", problem.grader) - if grader.grade(flag): - solve = Solves(pid, tid, flag, True) - db.session.add(solve) - db.session.commit() + if problem: + grader = imp.load_source("grader", problem.grader) + correct, response = grader.grade(flag) + + solve = Solves(pid, tid, flag, correct) + db.session.add(solve) + db.session.commit() + + if correct: logger.log(__name__, "%s has solved %s by submitting %s" % (team.teamname, problem.title, flag), level=logger.WARNING) - return { "success": 1, "message": "Correct!" } + return { "success": 1, "message": response } else: - solve = Solves(pid, tid, flag, False) - db.session.add(solve) - db.session.commit() logger.log(__name__, "%s has incorrectly submitted %s to %s" % (team.teamname, flag, problem.title), level=logger.WARNING) - raise WebException("Incorrect.") + raise WebException(response) else: raise WebException("Problem does not exist!")