Skip to content
Snippets Groups Projects

Toggling pregrading and Identifying blank solutions

Open Ghost User requested to merge feature/toggle-pregrading into develop
Compare and Show latest version
3 files
+ 17
30
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 19
11
@@ -3,8 +3,7 @@
import os
from flask_restful import Resource, reqparse, current_app
from zesje.database import db, Exam, Problem, ProblemWidget, Solution
from ..database import db, Exam, Problem, ProblemWidget, Solution, FeedbackOption, GradingPolicy
from zesje.pdf_reader import guess_problem_title, get_problem_page
@@ -19,6 +18,7 @@ class Problems(Resource):
post_parser.add_argument('y', type=int, required=True, location='form')
post_parser.add_argument('width', type=int, required=True, location='form')
post_parser.add_argument('height', type=int, required=True, location='form')
post_parser.add_argument('grading_policy', type=int, required=True, location='form')
def post(self):
"""Add a new problem.
@@ -48,6 +48,7 @@ class Problems(Resource):
exam=exam,
name=args['name'],
widget=widget,
grading_policy=GradingPolicy(args['grading_policy'])
)
# Widget is also added because it is used in problem
@@ -72,6 +73,10 @@ class Problems(Resource):
db.session.commit()
new_feedback_option = FeedbackOption(problem_id=problem.id, text='blank', score=0)
db.session.add(new_feedback_option)
db.session.commit()
return {
'id': problem.id,
'widget_id': widget.id,
@@ -79,31 +84,34 @@ class Problems(Resource):
}
put_parser = reqparse.RequestParser()
put_parser.add_argument('name', type=str, required=True)
put_parser.add_argument('name', type=str)
put_parser.add_argument('grading_policy', type=int)
def put(self, problem_id, attr):
def put(self, problem_id):
"""PUT to a problem
As of writing this method only supports putting the name property
This method accepts both the problem name and the grading policy.
problem_id: int
the problem id to put to
attr: str
the attribute (or property) to put to (only supports 'name' now)
the attribute (or property) to put to
Returns
HTTP 200 on success
HTTP 200 on success, 404 if the problem does not exist
"""
args = self.put_parser.parse_args()
name = args['name']
problem = Problem.query.get(problem_id)
if problem is None:
msg = f"Problem with id {problem_id} doesn't exist"
return dict(status=404, message=msg), 404
return dict(status=404, message=f"Problem with id {problem_id} doesn't exist"), 404
for attr, value in args.items():
if value is not None:
setattr(problem, attr, value)
problem.name = name
db.session.commit()
return dict(status=200, message="ok"), 200
Loading