Check for syntax errors in new graders

This commit is contained in:
James Wang 2016-04-17 08:58:32 -04:00
parent aa4f19d976
commit d3371e5417
No known key found for this signature in database
GPG key ID: 5B80C0B3F263CD5B

View file

@ -32,6 +32,11 @@ def problem_add():
if title_exist:
raise WebException("Problem name already taken.")
try:
exec(grader_contents)
except Exception, e:
raise WebException("There is a syntax error in the grader: %s" % e)
problem = Problems(pid, title, category, description, value, hint=hint)
db.session.add(problem)
db.session.commit()
@ -87,6 +92,10 @@ def problem_update():
hint = request.form["hint"]
value = request.form["value"]
grader_contents = request.form["grader_contents"]
try:
exec(grader_contents)
except Exception, e:
raise WebException("There is a syntax error in the grader: %s" % e)
problem = Problems.query.filter_by(pid=pid).first()
if problem: