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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Réouven ASSOULY
zesje
Commits
d580fbd0
Commit
d580fbd0
authored
7 years ago
by
Joseph Weston
Browse files
Options
Downloads
Patches
Plain Diff
add helpers for making API parameters required
parent
b91182a4
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
zesje/resources/_helpers.py
+10
-0
10 additions, 0 deletions
zesje/resources/_helpers.py
zesje/resources/exams.py
+6
-5
6 additions, 5 deletions
zesje/resources/exams.py
zesje/resources/graders.py
+10
-11
10 additions, 11 deletions
zesje/resources/graders.py
with
26 additions
and
16 deletions
zesje/resources/_helpers.py
0 → 100644
+
10
−
0
View file @
d580fbd0
def
nonempty_string
(
s
):
s
=
str
(
s
)
if
not
s
:
raise
ValueError
(
'
cannot be an empty string
'
)
return
s
def
required_string
(
parser
,
name
):
parser
.
add_argument
(
name
,
type
=
nonempty_string
,
required
=
True
,
nullable
=
False
)
This diff is collapsed.
Click to expand it.
zesje/resources/exams.py
+
6
−
5
View file @
d580fbd0
...
...
@@ -7,9 +7,9 @@ from werkzeug.datastructures import FileStorage
from
pony
import
orm
from
..helpers
import
yaml_helper
from
..helpers
import
yaml_helper
,
db_helper
from
..models
import
db
,
Exam
,
Problem
,
FeedbackOption
from
.
.
helpers
import
db_helper
from
.
_
helpers
import
required_string
class
ExamConfig
(
Resource
):
...
...
@@ -31,11 +31,12 @@ class ExamConfig(Resource):
'
yaml
'
:
yml
}
patch_parser
=
reqparse
.
RequestParser
()
required_string
(
patch_parser
,
'
yaml
'
)
@orm.db_session
def
patch
(
self
,
id
):
parser
=
reqparse
.
RequestParser
()
parser
.
add_argument
(
'
yaml
'
,
type
=
str
,
required
=
True
)
args
=
parser
.
parse_args
()
args
=
patch_parser
.
parse_args
()
exam
=
Exam
[
id
]
...
...
This diff is collapsed.
Click to expand it.
zesje/resources/graders.py
+
10
−
11
View file @
d580fbd0
...
...
@@ -6,15 +6,12 @@ from flask_restful import Resource, reqparse
from
pony
import
orm
from
..models
import
db
,
Grader
from
._helpers
import
required_string
parser
=
reqparse
.
RequestParser
()
parser
.
add_argument
(
'
first_name
'
,
type
=
str
,
required
=
True
)
parser
.
add_argument
(
'
last_name
'
,
type
=
str
,
required
=
True
)
# TODO: when making new database structure, have only a single
# 'name' field: it is just an identifier
class
Graders
(
Resource
):
"""
Graders that are able to use the software, also logged during grading
"""
...
...
@@ -42,6 +39,10 @@ class Graders(Resource):
for
g
in
Grader
.
select
()
]
post_parser
=
reqparse
.
RequestParser
()
required_string
(
post_parser
,
'
first_name
'
)
required_string
(
post_parser
,
'
last_name
'
)
@orm.db_session
def
post
(
self
):
"""
add a grader.
...
...
@@ -58,15 +59,13 @@ class Graders(Resource):
first_name: str
last_name: str
"""
args
=
parser
.
parse_args
()
args
=
post_parser
.
parse_args
()
try
:
Grader
(
first_name
=
args
[
'
first_name
'
],
last_name
=
args
[
'
last_name
'
])
last_name
=
args
[
'
last_name
'
])
orm
.
commit
()
except
KeyError
as
_
e
:
abort
(
400
,
_
e
)
except
KeyError
as
e
rror
:
abort
(
400
,
e
rror
)
return
self
.
_get
()
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