Commit 97b46ece authored by Herman Andersen Dyrkorn's avatar Herman Andersen Dyrkorn
Browse files

Merge branch '38-fix-temp-image-bug' into 'master'

Resolve "fix temp image bug"

Closes #38

See merge request !41
parents c6d92dd2 d1541ac2
......@@ -7,6 +7,7 @@ import os
from api import limiter
from image_encoder.image_encoder import *
from path_constants import image_type
import glob
# import mimetypes
ALLOWED_EXTENSIONS = ['jpg', 'png', 'jpeg']
......@@ -25,6 +26,9 @@ class FindSalamanderInfo(Resource):
if image.filename != '':
if image and allowed_image(image.filename):
temp_img_path = os.path.abspath("./temp_images/")
list_of_temp_images = glob.glob(os.path.join(temp_img_path, str(user_id) + '*.*'))
for temp_image in list_of_temp_images:
os.remove(temp_image)
image.filename = str(user_id) + "." + extension(image.filename)
image.save(os.path.join(temp_img_path, image.filename))
......
......@@ -8,6 +8,7 @@ import re
import os
from api.endpoints.matchsalamander import sanitize_int_str
from path_constants import _ACCESS_DATABASE
LATITUDE_REGEX = "^(\\+|-)?(?:90(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\\.[0-9]{1,6})?))$"
LONGITUDE_REGEX = "^(\\+|-)?(?:180(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\\.[0-9]{1,6})?))$"
......@@ -24,9 +25,9 @@ class LocationEndpoint(Resource):
with _ACCESS_DATABASE:
location = db.session.query(Location).filter_by(name=data['name'].lower()).first()
if location is None and re.search(LATITUDE_REGEX, data['latitude']) and re.search(LONGITUDE_REGEX,
data['longitude']):
data['longitude']):
new_location = Location(name=data['name'].lower(), longitude=data['longitude'],
latitude=data['latitude'], radius=sanitize_int_str(str(data['radius'])))
latitude=data['latitude'], radius=sanitize_int_str(str(data['radius'])))
db.session.add(new_location)
db.session.commit()
create_directory_folders(data['name'].lower())
......@@ -76,8 +77,9 @@ class LocationEndpoint(Resource):
else:
return jsonify({"message": "location doesn't exist", "status": 400})
else:
return jsonify({"message": "location needs to be empty." + " There are " + str(len(salamanders))
+ " salamanders in this location.", "status": 400})
return jsonify(
{"message": "location needs to be empty." + " There are " + str(len(salamanders))
+ " salamanders in this location.", "status": 400})
else:
return jsonify({"message": "query failed", "status": 400})
else:
......
......@@ -8,10 +8,10 @@ from api import db, limiter
from api.models.dbmodels import Salamander, SalamanderGrowth, Location
from algorithm.brute_force_matching import match_file_structure
from path_constants import _ACCESS_DATABASE
import glob
APPROVED_SEX = ["male", "female", "juvenile"]
APPROVED_SPECIES = ["smooth_newt", "northern_crested_newt"]
import glob
# matchSalamander endpoint
......
......@@ -8,6 +8,7 @@ import glob
from image_encoder.image_encoder import *
from path_constants import _ACCESS_DATABASE
# get all images on a specific salamander based on id
class SalamanderEndpoint(Resource):
decorators = [limiter.limit("60/minute")]
......
......@@ -10,6 +10,7 @@ import glob
from shutil import move
from path_constants import _ACCESS_DATABASE
class SalamanderClass(Resource):
decorators = [limiter.limit("60/minute")]
......@@ -108,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)
else:
return jsonify({"message": "Salamander image, " + data['image_id'] + " does not exist", 'status': 400})
# if last image was moved:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment