-
Notifications
You must be signed in to change notification settings - Fork 0
/
validations.py
53 lines (47 loc) · 1.24 KB
/
validations.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
47
48
49
50
51
52
53
def check_parameter_existence(request, key):
if request.args.get(key) is None:
code = 400
response = {
'status': 'fail',
'data': {
key: 'Parameter is required.'
}
}
return False, code, response
return True, None, None
def check_comma_delimited(request, key):
if ',' not in request.args.get(key):
code = 400
response = {
'status': 'fail',
'data': {
key: 'Parameter should be comma delimited.'
}
}
return False, code, response
return True, None, None
def check_non_zero(value, key):
code = 400
response = {
'status': 'fail',
'data': {
key: 'Parameter should not be empty.'
}
}
if value is None:
return False, code, response
if len(value) < 1:
return False, code, response
return True, None, None
def check_numeric(value, key):
try:
float(value)
except ValueError:
code = 400
response = {
'status': 'fail',
'data': {
key: 'Parameter should be numeric.'
}
}
return False, code, response