def photo(): photo_id = request.args.get('id') photo = Photo.fetch_by_id(photo_id) metadata_exists = "False" taken_str = "Unknown Year" if photo.taken: taken_str = photo.taken.strftime("%Y") metadata_exists = "True" if photo.taken_lat: metadata_exists = "True" photo_dict = { "id": photo.id, "lat": photo.taken_lat, "lng": photo.taken_lon, "taken": photo.taken_str, "title": photo.title, "url": "https://res.cloudinary.com/dixpjmvss/image/upload/" + photo.pic, "collection": photo.collection_id, "thumbnail": "https://res.cloudinary.com/dixpjmvss/image/upload/" + photo.pic } photo_json = json.dumps(photo_dict) loaded_photo = json.loads(photo_json) return render_template('photo.html', photo=loaded_photo, metadata=metadata_exists)
def geotag_photo(): photo_id = request.args.get('id') photo = Photo.fetch_by_id(photo_id) lat = DEFAULT_LAT lng = DEFAULT_LNG if photo.taken_lat: lat = photo.taken_lat lng = photo.taken_lon taken_coords = (photo.taken_lat, photo.taken_lon) date = '2021-01-01' if photo.taken: date = photo.taken.strftime('%Y-%m-%d') url = "https://res.cloudinary.com/dixpjmvss/image/upload/" + photo.pic photo_dict = { "id": photo.id, "taken_coords": taken_coords, "taken": photo.taken_str, "title": photo.title, "angle": -1, "url": "https://res.cloudinary.com/dixpjmvss/image/upload/" + photo.pic, "collection": photo.collection_id, "thumbnail": "https://res.cloudinary.com/dixpjmvss/image/upload/" + photo.pic, "pic": photo.pic } session['photo'] = photo_dict return render_template("details.html", lat=lat, lon=lng, url=url, date=date, show_success_modal=True)
def add_camera(): if 'photo' in session: photo = session['photo'] db_photo = None collection_id = None taken_coords = photo['taken_coords'] # Check if the photo is already in the database if 'id' in photo.keys(): db_photo = Photo.fetch_by_id(photo['id']) collection_id = db_photo.collection_id loc_new = request.form.get("loc_new") loc_id = request.form.get("loc_id") lat = request.form.get("lat2") lon = request.form.get("lon2") # Update destination coords dest_coords = (lat, lon) photo['dest_coords'] = dest_coords if loc_id: print("add to location") location = Location.query.get(loc_id) location.add_photo(db_photo) else: print("new location") loc_name = "Untitled" if loc_new: loc_name = loc_new location = Location(lat=lat, lon=lon, name=loc_name) if not db_photo: db_photo = Photo(pic=photo['pic'], taken=photo['taken'], coords=dest_coords, taken_coords=photo['taken_coords'], loc=location, title=photo['title']) else: db_photo.update(pic=photo['pic'], taken=photo['taken'], coords=dest_coords, taken_coords=photo['taken_coords'], loc=location, title=photo['title']) location.add_photo(db_photo) # Remove photo from collection if collection_id: db_photo.remove_collection() collection = Collection.fetch_by_id(collection_id) # If collection is empty, delete it if len(collection.c_photos) == 0: collection.delete() # # Add to location # new_loc = None # # Very very inefficient # locations = Location.fetch_all() # for location in locations: # if location.equals(lat, lon): # new_loc = location # break # if new_loc is None: # new_loc = Location(lat=lat, lon=lon) # new_loc.add_photo(Photo(pic=photo['pic'], taken=photo['taken'], coords = dest_coords, # taken_coords=photo['taken_coords'], loc=new_loc)) session.pop('photo') else: return redirect("/") return redirect("/")