Skip to content
Snippets Groups Projects
Commit 31492728 authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

tell which submissions miss pages

parent d45267cf
No related branches found
No related tags found
No related merge requests found
import re
from flask_restful import Resource, reqparse
from pony import orm
from ..models import Exam, Submission, Student
page_match = re.compile(r'.*page(\d+).jpg').match
def page_nr(path):
return int(page_match(path).group(1))
def sub_to_data(sub, all_pages):
"""Transform a submission into a data structure frontend expects."""
return {
'id': sub.copy_number,
'student':
{
'id': sub.student.id,
'firstName': sub.student.first_name,
'lastName': sub.student.last_name,
'email': sub.student.email
} if sub.student else None,
'validated': sub.signature_validated,
'problems':
[
{
'id': sol.problem.id,
'graded_by': sol.graded_by,
'graded_at': sol.graded_at.isoformat() if sol.graded_at else None,
'feedback': [
fb.id for fb in sol.feedback
],
'remark': sol.remarks
} for sol in sub.solutions.order_by(lambda s: s.problem.id)
],
'missing_pages': sorted(all_pages - set(page_nr(i) for i in sub.pages.path)),
}
class Submissions(Resource):
"""Getting a list of submissions, and assigning students to them."""
......@@ -26,62 +63,27 @@ class Submissions(Resource):
Student that completed this submission, null if not assigned.
validated: bool
True if the assigned student has been validated by a human.
problems: list of problems
missing_pages: list of int
pages that are missing from submission
"""
# This makes sure we raise ObjectNotFound if the exam does not exist
exam = Exam[exam_id]
all_pages = set(page_nr(i) for i in exam.submissions.pages.path)
if submission_id is not None:
sub = Submission.get(exam=exam, copy_number=submission_id)
if not sub:
raise orm.core.ObjectNotFound(Submission)
return {
'id': sub.copy_number,
'student':
{
'id': sub.student.id,
'firstName': sub.student.first_name,
'lastName': sub.student.last_name,
'email': sub.student.email
} if sub.student else None,
'validated': sub.signature_validated,
'problems':
[
{
'id': sol.problem.id,
'graded_by': sol.graded_by,
'graded_at': sol.graded_at.isoformat() if sol.graded_at else None,
'feedback': [
fb.id for fb in sol.feedback
],
'remark': sol.remarks
} for sol in sub.solutions.order_by(lambda s: s.problem.id)
]
}
return sub_to_data(sub, all_pages)
return [
{
'id': sub.copy_number,
'student':
{
'id': sub.student.id,
'firstName': sub.student.first_name,
'lastName': sub.student.last_name,
'email': sub.student.email
} if sub.student else None,
'validated': sub.signature_validated,
'problems':
[
{
'id': sol.problem.id,
'graded_by': sol.graded_by,
'graded_at': sol.graded_at.isoformat() if sol.graded_at else None,
'feedback': [
fb.id for fb in sol.feedback
],
'remark': sol.remarks
} for sol in sub.solutions.order_by(lambda s: s.problem.id)
]
} for sub in Submission.select(lambda s: s.exam == exam).order_by(lambda s: s.copy_number)
sub_to_data(sub, all_pages) for sub
in (Submission
.select(lambda s: s.exam == exam)
.order_by(lambda s: s.copy_number))
]
put_parser = reqparse.RequestParser()
......
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