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

add endpoint for getting student signature images

parent e41b9fea
Branches
Tags
No related merge requests found
......@@ -6,6 +6,7 @@ from .resources.exams import Exams, ExamConfig
from .resources.pdfs import Pdfs
from .resources.students import Students
from .resources.submissions import Submissions
from .resources import signature
api_bp = Blueprint(__name__, __name__)
......@@ -26,3 +27,12 @@ api.add_resource(Students, '/students')
api.add_resource(Submissions,
'/submissions/<int:exam_id>',
'/submissions/<int:exam_id>/<int:submission_id>')
# Other resources that don't return JSON
# It is possible to get flask_restful to work with these, but not
# very idiomatic.
api_bp.add_url_rule(
'/images/signature/<int:exam_id>/<int:submission_id>',
'signature',
signature.get,
)
from flask import abort, Response
from pony import orm
from ..helpers import yaml_helper, image_helper
from ..models import Exam, Submission
@orm.db_session
def get(exam_id, submission_id):
"""get student signature for the given submission.
Parameters
----------
exam_id : int
submission_id : int
The copy number of the submission. This uniquely identifies
the submission *within a given exam*.
Returns
-------
Image (JPEG mimetype)
"""
# We could register an app-global error handler for this,
# but it would add more code then it removes.
exam = Exam.get(id=exam_id)
if not exam:
abort(404)
sub = Submission.get(exam=exam, copy_number=submission_id)
if not sub:
abort(404)
*_, widgets = yaml_helper.parse(yaml_helper.read(sub.exam.yaml_path))
first_page = next(p.path for p in sub.pages if 'page1' in p.path)
image = image_helper.get_widget_image(first_page,
widgets.loc['studentnr'])
return Response(image, 200, mimetype='image/jpeg')
......@@ -13,6 +13,9 @@ class Submissions(Resource):
Parameters
----------
exam_id : int
submission_id : int, optional
The copy number of the submission. This uniquely identifies
the submission *within a given exam*.
Returns
-------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment