-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidators.py
46 lines (40 loc) · 1.28 KB
/
validators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from django.core.exceptions import ValidationError
def validate_results_request(data):
"""
Validates that a result request dictionary has all needed parameters
and their type is correct.
Throws ValidationError on error.
"""
mandatory_data = [
'env',
'proj',
'branch',
'exe',
'ben',
]
for key in mandatory_data:
if key not in data:
raise ValidationError('Key "' + key +
'" missing from GET request!')
elif data[key] == '':
raise ValidationError('Value for key "' + key +
'" empty in GET request!')
integer_data = [
'revs',
'width',
'height'
]
"""
Check that the items in integer_data are the correct format,
if they exist
"""
for key in integer_data:
if key in data:
try:
rev_value = int(data[key])
except ValueError:
raise ValidationError('Value for "' + key +
'" is not an integer!')
if rev_value <= 0:
raise ValidationError('Value for "' + key + '" should be a'
' strictly positive integer!')