diff --git a/api/endpoints/editsalamander.py b/api/endpoints/editsalamander.py index 50adb7fb5f8fda5c21c773e8c9f09a8644e5c7f5..fb93d1e6741da96a7ac87e341ee41ec47259854e 100644 --- a/api/endpoints/editsalamander.py +++ b/api/endpoints/editsalamander.py @@ -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.: