Skip to content
Snippets Groups Projects

Resolve "refactor edit salamander"

Merged Herman Andersen Dyrkorn requested to merge 47-refactor-edit-salamander into master
1 file
+ 6
12
Compare changes
  • Side-by-side
  • Inline
+ 6
12
@@ -138,19 +138,15 @@ class EditSalamander(Resource):
@@ -138,19 +138,15 @@ class EditSalamander(Resource):
if salamander:
if salamander:
growth_row = db.session.query(SalamanderGrowth).filter_by(salamander_id=salamander.id,
growth_row = db.session.query(SalamanderGrowth).filter_by(salamander_id=salamander.id,
image_id=int(data['image_id'])).first()
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']))
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']))
growth_row.length = sanitize_number_str(str(data['length']))
db.session.commit()
db.session.commit()
 
if "location" in data and "new_location" in data and "new_sex" in data and "new_species" in data:
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 \
if data['location'] != data['new_location'] or salamander.sex != data['new_sex'] or salamander.species != data['new_species']:
salamander.species != data['new_species']:
salamander_path = os.path.join("images", data['location'], salamander.species, salamander.sex, str(salamander.id))
salamander_path = os.path.join("images", data['location'], salamander.species,
new_path_to_images = os.path.join("images", data['new_location'], data['new_species'], data['new_sex'])
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'] + '.*'))
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.*'))
processed_path = glob.glob(os.path.join(salamander_path, data['image_id'] + '_str.*'))
if len(original_path) > 0 and len(processed_path) > 0:
if len(original_path) > 0 and len(processed_path) > 0:
@@ -160,10 +156,8 @@ class EditSalamander(Resource):
@@ -160,10 +156,8 @@ class EditSalamander(Resource):
last_id = int(len(os.listdir(salamander_path)) / 2) - 1
last_id = int(len(os.listdir(salamander_path)) / 2) - 1
if data['new_sex'] != "juvenile":
if data['new_sex'] != "juvenile":
result = match_file_structure(input_image=processed_path,
result = match_file_structure(input_image=processed_path, match_directory=new_path_to_images)
match_directory=new_path_to_images)
if result:
if result:
# if salamander already exist:
# if salamander already exist:
if result > -1:
if result > -1:
# move all images and delete previous ID.:
# move all images and delete previous ID.:
Loading