Adding extra validators for the name
This commit is contained in:
parent
e285131e8b
commit
11b410f985
1 changed files with 7 additions and 0 deletions
|
@ -52,8 +52,14 @@ def result_post():
|
||||||
cpu = content['cpu']
|
cpu = content['cpu']
|
||||||
log = content['log']
|
log = content['log']
|
||||||
score = int(content['score'])
|
score = int(content['score'])
|
||||||
|
|
||||||
|
# Extra validators
|
||||||
if score <= 0:
|
if score <= 0:
|
||||||
raise ValueError("Score must be positive!")
|
raise ValueError("Score must be positive!")
|
||||||
|
if any(c.isspace() for c in name):
|
||||||
|
raise ValueError("Name can't contain spaces!")
|
||||||
|
if not name.isalnum():
|
||||||
|
raise ValueError("Name must contain only letters and numbers!")
|
||||||
except KeyError as e: # Json doesn't contain the keys we need.
|
except KeyError as e: # Json doesn't contain the keys we need.
|
||||||
error = "Key not found: {}.".format(str(e))
|
error = "Key not found: {}.".format(str(e))
|
||||||
except TypeError as e: # If we don't get a string
|
except TypeError as e: # If we don't get a string
|
||||||
|
@ -71,6 +77,7 @@ def result_post():
|
||||||
location = "/result/{}".format(entry.id)
|
location = "/result/{}".format(entry.id)
|
||||||
|
|
||||||
return flask.jsonify({'success': True}), 201, {'location': location}
|
return flask.jsonify({'success': True}), 201, {'location': location}
|
||||||
|
|
||||||
# Exception occurred
|
# Exception occurred
|
||||||
return flask.jsonify({'error': error, 'success': False}), 400
|
return flask.jsonify({'error': error, 'success': False}), 400
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue