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

implement solution images endpoint

parent 7853b1b1
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ from .resources.pdfs import Pdfs
from .resources.students import Students
from .resources.submissions import Submissions
from .resources import signature
from .resources import images
from .resources.problems import Problems
from .resources.feedback import Feedback
......@@ -41,3 +42,8 @@ api_bp.add_url_rule(
'signature',
signature.get,
)
api_bp.add_url_rule(
'/images/solutions/<int:exam_id>/<int:problem_id>/<int:submission_id>',
'solution',
images.get,
)
import os
from flask import abort, Response, current_app as app
from pony import orm
from ..helpers import yaml_helper, image_helper
from ..models import Exam, Submission, Solution, Problem
@orm.db_session
def get(exam_id, problem_id, submission_id):
"""get student signature for the given submission.
Parameters
----------
exam_id : int
problem_id : int
submission_id : int
The copy number of the submission. This uniquely identifies
the submission *within a given exam*.
Returns
-------
Image (JPEG mimetype)
"""
try:
exam = Exam[exam_id]
sub = Submission.get(exam=exam, copy_number=submission_id)
name = Problem[problem_id].name
except (KeyError, ValueError):
abort(404)
data_dir = app.config['DATA_DIRECTORY']
yaml_abspath = os.path.join(data_dir, sub.exam.yaml_path)
*_, widgets = yaml_helper.parse(yaml_helper.read(yaml_abspath))
problem_metadata = widgets.loc[name]
page = f'page{int(problem_metadata.page)}.'
page_path = (
sub.pages
.select(lambda p: page in p.path)
.first().path
)
image = image_helper.get_widget_image(
page_path,
problem_metadata
)
return Response(image, 200, mimetype='image/jpeg')
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