Skip to content
Snippets Groups Projects
Commit 698c95b7 authored by Joseph Weston's avatar Joseph Weston
Browse files

add 'Submissions' resource for getting list of submissions

parent f6f635d0
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ from .resources.graders import Graders
from .resources.exams import Exams, ExamConfig
from .resources.pdfs import Pdfs
from .resources.students import Students
from .resources.submissions import Submissions
api_bp = Blueprint(__name__, __name__)
......@@ -22,3 +23,6 @@ api.add_resource(Exams, '/exams')
api.add_resource(ExamConfig, '/exams/<int:exam_id>')
api.add_resource(Pdfs, '/pdfs/<int:exam_id>')
api.add_resource(Students, '/students')
api.add_resource(Submissions,
'/submissions/<int:exam_id>',
'/submissions/<int:exam_id>/<int:copy_number>')
from flask_restful import Resource
from pony import orm
from ..models import Exam, Submission
class Submissions(Resource):
"""Getting a list of submissions, and assigning students to them."""
@orm.db_session
def get(self, exam_id, copy_number=None):
"""get submissions for the given exam
Parameters
----------
exam_id : int
Returns
-------
If 'copy_number' not provided provides a single instance of
(otherwise a list of):
copy_number: int
student_id: int or null
Student that completed this submission, null if not assigned.
validated: bool
True if the assigned student has been validated by a human.
"""
# This makes sure we raise ObjectNotFound if the exam does not exist
exam = Exam[exam_id]
if copy_number is not None:
s = Submission.get(exam=exam, copy_number=copy_number)
if not s:
raise orm.core.ObjectNotFound(Submission)
return {
'copy_number': s.copy_number,
'student_id': s.student.id if s.student else None,
'validated': s.signature_validated,
}
return [
{
'copy_number': s.copy_number,
'student': s.student.id if s.student else None,
'validated': s.signature_validated,
}
for s in Submission.select(lambda s: s.exam == exam)
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment