Skip to content

Commit

Permalink
fix device date constraint #11
Browse files Browse the repository at this point in the history
  • Loading branch information
HamoudaAmine committed Jun 8, 2020
1 parent 275cd1e commit 48dffbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions api/animals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@ def animals_validate_required(animal):
name = animal.get('name').lower()
name = name.strip()
animal_exist = Animal.query.filter(Animal.name == name).first()
if (animal_exist and (animal_exist.json().get('id') != animal.get('id'))):
if (animal_exist and (animal_exist.json().get('id_animal') != animal.get('id'))):
errors.append({
'name': 'attribute_already_exists',
'table': 'animals',
'column': 'name'
})
print ('animal_exist', animal_exist)
if len(errors) >= 0:
return {'errors': errors}
return True
Expand All @@ -160,9 +161,11 @@ def animals_validate_required(animal):
def check_devices_available(id=id):
try:
id_device = int(request.args.get('deviceId'))
id_animal = int(request.args.get('animalId'))
except Exception:
return jsonify(error='Invalid JSON.')
return jsonify(error='Invalid JSON.'),400
id_animal = request.args.get('animalId')
if id_animal:
id_animal = int(id_animal)
try:
now = datetime.now()
device_exist = AnimalDevice.query.filter(
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ Mode developpement
::

source venv/bin/activate
FLASK_APP=./appy FLASK_DEBUG=1 flask run
FLASK_APP=./app FLASK_DEBUG=1 flask run

0 comments on commit 48dffbc

Please sign in to comment.