Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
zesje
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Works on my machine
zesje
Commits
2158120a
Commit
2158120a
authored
5 years ago
by
Ruben Young On
Browse files
Options
Downloads
Patches
Plain Diff
Fixed fetching checkbox data
parent
c1e60023
No related branches found
No related tags found
1 merge request
!6
Draw pdf box
Pipeline
#17458
passed
5 years ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
zesje/api/__init__.py
+2
-0
2 additions, 0 deletions
zesje/api/__init__.py
zesje/api/exams.py
+53
-44
53 additions, 44 deletions
zesje/api/exams.py
zesje/api/test.py
+12
-0
12 additions, 0 deletions
zesje/api/test.py
with
67 additions
and
44 deletions
zesje/api/__init__.py
+
2
−
0
View file @
2158120a
...
...
@@ -12,6 +12,7 @@ from .solutions import Solutions
from
.widgets
import
Widgets
from
.emails
import
EmailTemplate
,
RenderedEmailTemplate
,
Email
from
.mult_choice
import
MultipleChoice
from
.test
import
Test
from
.
import
signature
from
.
import
images
...
...
@@ -51,6 +52,7 @@ api.add_resource(Email,
'
/email/<int:exam_id>
'
,
'
/email/<int:exam_id>/<int:student_id>
'
)
api
.
add_resource
(
MultipleChoice
,
'
/mult-choice/<int:id>
'
)
api
.
add_resource
(
Test
,
'
/test/
'
)
# Other resources that don't return JSON
...
...
This diff is collapsed.
Click to expand it.
zesje/api/exams.py
+
53
−
44
View file @
2158120a
...
...
@@ -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
):
def
get
(
self
,
exam_id
=
None
):
...
...
@@ -93,30 +122,30 @@ class Exams(Resource):
return
dict
(
status
=
404
,
message
=
'
Exam does not exist.
'
),
404
submissions
=
[
{
'
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
'
:
{
'
id
'
:
sol
.
graded_by
.
id
,
'
name
'
:
sol
.
graded_by
.
name
}
if
sol
.
graded_by
else
None
,
'
graded_at
'
:
sol
.
graded_at
.
isoformat
()
if
sol
.
graded_at
else
None
,
'
feedback
'
:
[
fb
.
id
for
fb
in
sol
.
feedback
],
'
remark
'
:
sol
.
remarks
if
sol
.
remarks
else
""
}
for
sol
in
sub
.
solutions
# Sorted by sol.problem_id
],
}
for
sub
in
exam
.
submissions
{
'
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
'
:
{
'
id
'
:
sol
.
graded_by
.
id
,
'
name
'
:
sol
.
graded_by
.
name
}
if
sol
.
graded_by
else
None
,
'
graded_at
'
:
sol
.
graded_at
.
isoformat
()
if
sol
.
graded_at
else
None
,
'
feedback
'
:
[
fb
.
id
for
fb
in
sol
.
feedback
],
'
remark
'
:
sol
.
remarks
if
sol
.
remarks
else
""
}
for
sol
in
sub
.
solutions
# Sorted by sol.problem_id
],
}
for
sub
in
exam
.
submissions
]
# Sort submissions by selecting those with students assigned, then by
# student number, then by copy number.
...
...
@@ -325,26 +354,6 @@ class ExamGeneratedPdfs(Resource):
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
.
add_argument
(
'
copies_start
'
,
type
=
int
,
required
=
True
)
post_parser
.
add_argument
(
'
copies_end
'
,
type
=
int
,
required
=
True
)
...
...
This diff is collapsed.
Click to expand it.
zesje/api/test.py
0 → 100644
+
12
−
0
View file @
2158120a
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment