Skip to content
Snippets Groups Projects
Commit f7e39e1c authored by Herman Andersen Dyrkorn's avatar Herman Andersen Dyrkorn
Browse files

returns for matched salamanders when edited

parent 0dc4059d
No related branches found
No related tags found
No related merge requests found
......@@ -109,7 +109,7 @@ class SalamanderClass(Resource):
else:
add_salamander(salamander.id, image_id, data['new_location'], data['new_species'],
data['new_sex'], new_path_to_images, user_id, original_path, processed_path)
return handle_remaining_images(salamander, salamander_path, image_id, last_id)
return handle_remaining_images(salamander, salamander_path, image_id, last_id, True, result)
else:
return jsonify({"message": "Salamander image, " + data['image_id'] + " does not exist", 'status': 400})
# if last image was moved:
......@@ -117,7 +117,7 @@ class SalamanderClass(Resource):
add_salamander(salamander.id, image_id, data['new_location'], data['new_species'],
data['new_sex'], new_path_to_images, user_id, original_path,
processed_path)
return handle_remaining_images(salamander, salamander_path, image_id, last_id)
return handle_remaining_images(salamander, salamander_path, image_id, last_id, False, 0)
else:
return jsonify({"message": "Image id, " + data['image_id'] + " does not exist in salamander_id, " + data['id'], 'status': 400})
else:
......@@ -137,13 +137,17 @@ def delete_growth_row(salamander_id, image_id):
db.session.commit()
def handle_remaining_images(salamander, salamander_path: str, image_id: int, last_id: int, ):
def handle_remaining_images(salamander, salamander_path: str, image_id: int, last_id: int, match_bool, result):
# if last image was moved:
if len(os.listdir(salamander_path)) == 0:
os.rmdir(salamander_path)
db.session.delete(salamander)
db.session.commit()
return jsonify({"id": salamander.id, "imageId": image_id, "message": "salamander moved", 'status': 200})
if match_bool:
return jsonify({"id": result, "matching": "Yes", 'status': 200})
else:
return jsonify({"id": salamander.id, "matching": "No", 'status': 200})
else:
if image_id != last_id:
original_path = glob.glob(os.path.join(salamander_path, str(last_id) + '.*'))[0]
......@@ -156,7 +160,10 @@ def handle_remaining_images(salamander, salamander_path: str, image_id: int, las
db.session.commit()
os.rename(processed_path, os.path.join(salamander_path, str(image_id) + "_str" + processed_extension))
os.rename(original_path, os.path.join(salamander_path, str(image_id) + original_extension))
return jsonify({"id": salamander.id, "message": "salamander moved", 'status': 200})
if match_bool:
return jsonify({"id": result, "matching": "Yes", 'status': 200})
else:
return jsonify({"id": salamander.id, "matching": "No", 'status': 200})
def lower_image_id_growth_row(salamander_id, old_id, new_id):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment