Skip to content
Snippets Groups Projects
Commit 2158120a authored by Ruben Young On's avatar Ruben Young On
Browse files

Fixed fetching checkbox data

parent c1e60023
No related branches found
No related tags found
1 merge request!6Draw pdf box
Pipeline #17458 passed
...@@ -12,6 +12,7 @@ from .solutions import Solutions ...@@ -12,6 +12,7 @@ from .solutions import Solutions
from .widgets import Widgets from .widgets import Widgets
from .emails import EmailTemplate, RenderedEmailTemplate, Email from .emails import EmailTemplate, RenderedEmailTemplate, Email
from .mult_choice import MultipleChoice from .mult_choice import MultipleChoice
from .test import Test
from . import signature from . import signature
from . import images from . import images
...@@ -51,6 +52,7 @@ api.add_resource(Email, ...@@ -51,6 +52,7 @@ api.add_resource(Email,
'/email/<int:exam_id>', '/email/<int:exam_id>',
'/email/<int:exam_id>/<int:student_id>') '/email/<int:exam_id>/<int:student_id>')
api.add_resource(MultipleChoice, '/mult-choice/<int:id>') api.add_resource(MultipleChoice, '/mult-choice/<int:id>')
api.add_resource(Test, '/test/')
# Other resources that don't return JSON # Other resources that don't return JSON
......
...@@ -25,6 +25,35 @@ def _get_exam_dir(exam_id): ...@@ -25,6 +25,35 @@ def _get_exam_dir(exam_id):
) )
def get_cb_data_for_exam(exam):
"""
Returns all multiple choice question check boxes for one specific exam
Parameters
----------
exam: the exam
Returns
-------
A list of tuples with checkbox data.
Each tuple is represented as (x, y, page, label)
Where
x: x position
y: y position
page: page number
label: checkbox label
"""
problem_ids = [problem.id for problem in exam.problems]
cb_data = MultipleChoiceOption.query.filter(MultipleChoiceOption.problem_id.in_(problem_ids)).all()
# Map to tuples with (x pos, y pos, page number, label)
cb_data = [(cb.x, cb.y, cb.page, cb.label) for cb in cb_data]
return cb_data
class Exams(Resource): class Exams(Resource):
def get(self, exam_id=None): def get(self, exam_id=None):
...@@ -93,30 +122,30 @@ class Exams(Resource): ...@@ -93,30 +122,30 @@ class Exams(Resource):
return dict(status=404, message='Exam does not exist.'), 404 return dict(status=404, message='Exam does not exist.'), 404
submissions = [ submissions = [
{ {
'id': sub.copy_number, 'id': sub.copy_number,
'student': { 'student': {
'id': sub.student.id, 'id': sub.student.id,
'firstName': sub.student.first_name, 'firstName': sub.student.first_name,
'lastName': sub.student.last_name, 'lastName': sub.student.last_name,
'email': sub.student.email 'email': sub.student.email
} if sub.student else None, } if sub.student else None,
'validated': sub.signature_validated, 'validated': sub.signature_validated,
'problems': [ 'problems': [
{ {
'id': sol.problem.id, 'id': sol.problem.id,
'graded_by': { 'graded_by': {
'id': sol.graded_by.id, 'id': sol.graded_by.id,
'name': sol.graded_by.name 'name': sol.graded_by.name
} if sol.graded_by else None, } if sol.graded_by else None,
'graded_at': sol.graded_at.isoformat() if sol.graded_at else None, 'graded_at': sol.graded_at.isoformat() if sol.graded_at else None,
'feedback': [ 'feedback': [
fb.id for fb in sol.feedback fb.id for fb in sol.feedback
], ],
'remark': sol.remarks if sol.remarks else "" 'remark': sol.remarks if sol.remarks else ""
} for sol in sub.solutions # Sorted by sol.problem_id } for sol in sub.solutions # Sorted by sol.problem_id
], ],
} for sub in exam.submissions } for sub in exam.submissions
] ]
# Sort submissions by selecting those with students assigned, then by # Sort submissions by selecting those with students assigned, then by
# student number, then by copy number. # student number, then by copy number.
...@@ -325,26 +354,6 @@ class ExamGeneratedPdfs(Resource): ...@@ -325,26 +354,6 @@ class ExamGeneratedPdfs(Resource):
cb_data=cb_data cb_data=cb_data
) )
def get_cb_data_for_exam(self, exam):
"""
Returns all multiple choice question check boxes for one specific exam
Parameters
----------
exam: the exam
Returns
-------
A list of MultipleChoiceQuestion objects that belong to the specified exam
"""
problem_ids = [problem.id for problem in exam.problems]
cb_data = MultipleChoiceOption.query.filter(MultipleChoiceOption.id in problem_ids).all()
return cb_data
def get_id(problem):
return problem.id
post_parser = reqparse.RequestParser() post_parser = reqparse.RequestParser()
post_parser.add_argument('copies_start', type=int, required=True) post_parser.add_argument('copies_start', type=int, required=True)
post_parser.add_argument('copies_end', type=int, required=True) post_parser.add_argument('copies_end', type=int, required=True)
......
from flask_restful import Resource
class Test(Resource):
"""
Class used to make test api calls
"""
def get(self):
# Call your code here, and edit the message to return specific objects
return dict(message='ok', code=200), 200
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