def add_photo_to_trip(): '''adds a photo to the trip board for that location''' trip_id = request.form.get('trip') img_id = request.form.get('img_id') url = request.form.get('url') lat = request.form.get('lat') lon = request.form.get('lon') city_name = request.form.get('city_name') trip = Trip.get_trip(trip_id) # checks if authorized user is accessing this page if session.get('login') == trip.user_id: # if photo is not in the database, add it to the database if not Photo.get_photo(img_id): photo = Photo(img_id=int(img_id), url=url, lon=float(lon), lat=float(lat), city_name=city_name) db.session.add(photo) db.session.commit() # check if photo already exists in current users trip already_exists = TripPhotoRelationship.get_trip_photo(trip_id, img_id) if already_exists: return 'This photo is already in your trip board!' # photo is not in current trip board, add relationship to the database else: trip_photo = TripPhotoRelationship(trip_id=trip_id, photo_id=img_id) db.session.add(trip_photo) db.session.commit() return 'Photo Added' # unauthorized user, redirect to homepage else: flash('You do not have permission to access this feature') return 'Unauthorized User: Photo Not Added'