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

refactoring edit salamandet PUT endpoint

parent cc3ffaf8
Branches
No related tags found
1 merge request!50Resolve "refactor edit salamander"
......@@ -138,19 +138,15 @@ class EditSalamander(Resource):
if salamander:
growth_row = db.session.query(SalamanderGrowth).filter_by(salamander_id=salamander.id,
image_id=int(data['image_id'])).first()
if "weight" in data:
if "weight" in data and "length" in data:
growth_row.weight = sanitize_number_str(str(data['weight']))
db.session.commit()
if "length" in data:
growth_row.length = sanitize_number_str(str(data['length']))
db.session.commit()
if "location" in data and "new_location" in data and "new_sex" in data and "new_species" in data:
if data['location'] != data['new_location'] or salamander.sex != data['new_sex'] or \
salamander.species != data['new_species']:
salamander_path = os.path.join("images", data['location'], salamander.species,
salamander.sex, str(salamander.id))
new_path_to_images = os.path.join("images", data['new_location'], data['new_species'],
data['new_sex'])
if data['location'] != data['new_location'] or salamander.sex != data['new_sex'] or salamander.species != data['new_species']:
salamander_path = os.path.join("images", data['location'], salamander.species, salamander.sex, str(salamander.id))
new_path_to_images = os.path.join("images", data['new_location'], data['new_species'], data['new_sex'])
original_path = glob.glob(os.path.join(salamander_path, data['image_id'] + '.*'))
processed_path = glob.glob(os.path.join(salamander_path, data['image_id'] + '_str.*'))
if len(original_path) > 0 and len(processed_path) > 0:
......@@ -160,10 +156,8 @@ class EditSalamander(Resource):
last_id = int(len(os.listdir(salamander_path)) / 2) - 1
if data['new_sex'] != "juvenile":
result = match_file_structure(input_image=processed_path,
match_directory=new_path_to_images)
result = match_file_structure(input_image=processed_path, match_directory=new_path_to_images)
if result:
# if salamander already exist:
if result > -1:
# move all images and delete previous ID.:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment