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
32245fb8
Commit
32245fb8
authored
5 years ago
by
Ruben Young On
Browse files
Options
Downloads
Patches
Plain Diff
Multiple choice request data is now sent via body
parent
0cf334b3
Branches
Branches containing commit
No related tags found
1 merge request
!5
Add multiple choice checkbox location to database
Pipeline
#17387
passed
5 years ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
zesje/api/__init__.py
+1
-3
1 addition, 3 deletions
zesje/api/__init__.py
zesje/api/mult_choice.py
+49
-12
49 additions, 12 deletions
zesje/api/mult_choice.py
with
50 additions
and
15 deletions
zesje/api/__init__.py
+
1
−
3
View file @
32245fb8
...
...
@@ -56,9 +56,7 @@ api.add_resource(RenderedEmailTemplate,
api
.
add_resource
(
Email
,
'
/email/<int:exam_id>
'
,
'
/email/<int:exam_id>/<int:student_id>
'
)
api
.
add_resource
(
MultipleChoice
,
'
/mult-choice/<int:id>/<int:x>/<int:y>/<string:label>/<int:problem_id>/<int:feedback_id>
'
,
'
/mult-choice/<int:id>
'
)
api
.
add_resource
(
MultipleChoice
,
'
/mult-choice/<int:id>
'
)
# Other resources that don't return JSON
...
...
This diff is collapsed.
Click to expand it.
zesje/api/mult_choice.py
+
49
−
12
View file @
32245fb8
from
flask_restful
import
Resource
from
flask_restful
import
Resource
,
reqparse
from
..database
import
db
,
MultipleChoiceOption
class
MultipleChoice
(
Resource
):
def
put
(
self
,
id
,
x
,
y
,
label
,
problem_id
,
feedback_id
):
"""
Adds a multiple choice option to the database
put_parser
=
reqparse
.
RequestParser
()
# Arguments that have to be supplied in the request body
put_parser
.
add_argument
(
'
x
'
,
type
=
int
,
required
=
True
)
put_parser
.
add_argument
(
'
y
'
,
type
=
int
,
required
=
True
)
put_parser
.
add_argument
(
'
label
'
,
type
=
str
,
required
=
True
)
put_parser
.
add_argument
(
'
problem_id
'
,
type
=
int
,
required
=
True
)
put_parser
.
add_argument
(
'
feedback_id
'
,
type
=
int
,
required
=
True
)
def
put
(
self
,
id
):
"""
Puts a multiple choice option to the database
If the specified ID is already present, the current option will be updated.
Parameters
----------
id: The id of the option
x: the x-location of the the option in pixels
y: the y-location of the the option in pixels
label: The label of the option, this is a single char
problem_id: Question to which this option is linked
feedback_id: Feedback to which this option is linked
id: The id of the multiple choice option
"""
mc_entry
=
MultipleChoiceOption
(
id
=
id
,
x
=
x
,
y
=
y
,
label
=
label
,
problem_id
=
problem_id
,
feedback_id
=
feedback_id
)
db
.
session
.
add
(
mc_entry
)
args
=
self
.
put_parser
.
parse_args
()
x
=
args
[
'
x
'
]
y
=
args
[
'
y
'
]
label
=
args
[
'
label
'
]
problem_id
=
args
[
'
problem_id
'
]
feedback_id
=
args
[
'
feedback_id
'
]
mc_entry
=
MultipleChoiceOption
.
query
.
get
(
id
)
# If entry is not present insert
if
not
mc_entry
:
mc_entry
=
MultipleChoiceOption
(
id
=
id
,
x
=
x
,
y
=
y
,
label
=
label
,
problem_id
=
problem_id
,
feedback_id
=
feedback_id
)
db
.
session
.
add
(
mc_entry
)
db
.
session
.
commit
()
return
dict
(
status
=
200
,
message
=
'
Multiple choice question inserted
'
),
200
# Otherwise, update current entry
mc_entry
.
x
=
x
mc_entry
.
y
=
y
mc_entry
.
label
=
label
mc_entry
.
problem_id
=
problem_id
mc_entry
.
feedback_id
=
feedback_id
db
.
session
.
commit
()
return
dict
(
status
=
200
,
message
=
"
ok
"
),
200
return
dict
(
status
=
200
,
message
=
'
Multiple choice question updated
'
),
200
def
get
(
self
,
id
):
"""
Fetches multiple choice option from the database
...
...
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