Skip to content
Snippets Groups Projects
Commit f09dd532 authored by Thomas Roos's avatar Thomas Roos
Browse files

New problems API

parent 805e1a36
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.problems import Problems
api_bp = Blueprint(__name__, __name__)
......@@ -27,6 +28,7 @@ api.add_resource(Students, '/students', '/students/<int:student_id>')
api.add_resource(Submissions,
'/submissions/<int:exam_id>',
'/submissions/<int:exam_id>/<int:submission_id>')
api.add_resource(Problems, '/problems/<int:exam_id>')
# Other resources that don't return JSON
# It is possible to get flask_restful to work with these, but not
......
""" REST api for problems """
from flask_restful import Resource
from pony import orm
from ..models import Exam, Problem
class Problems(Resource):
""" List of problems associated with a particular exam_id """
@orm.db_session
def get(self, exam_id):
"""get list of problems of exam
Returns
-------
list of:
id: int
name: str
"""
exam = Exam[exam_id]
return [
{
'id': problem.id,
'name': problem.name
}
for problem in Problem.select(lambda p: p.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