def photo_delete(photo_id): """ Delete specific file (with thumbnail) and delete DB record. :param photo_id: target photo id :return: Json data remove:fail or success """ app.logger.debug("Photo delete request: %s", photo_id) try: ## TODO #4 : Review following code to delete uploaded photo information in DynamoDB. ## -- begin -- photo = Photo.get(current_user.id, photo_id) photo.delete() ## -- end -- util.delete(app, photo.filename, current_user) flash('Successfully removed!') app.logger.debug('Successfully removed!') except Exception as e: app.logger.error(e) flash('Error occurred! Please try again.') return jsonify(remove='fail') return jsonify(remove='success')
def upload(): """ Photo file upload function :return: HTML template for upload form or uploaded photo list """ form = PhotoForm(request.form) if request.method == 'POST': app.logger.debug(form.data) app.logger.debug("form.taken_date.data:%s", form.taken_date.data) upload_photo = request.files['photo'] ext = (upload_photo.filename.rsplit('.', 1)[1]).lower() filename = secure_filename("{0}.{1}".format(uuid.uuid4(), ext)) taken_date = datetime.strptime(form.taken_date.data, "%Y:%m:%d %H:%M:%S") app.logger.debug("take_date:{0}".format(taken_date)) try: app.logger.debug(current_user) size = util.save(upload_photo, filename, current_user.email, app) photo = Photo(current_user.id, util.current_milli_time()) photo.tags = form.tags.data photo.desc = form.desc.data photo.filename_orig = upload_photo.filename photo.filename = filename photo.filesize = size photo.geotag_lat = form.lat.data photo.geotag_lng = form.lng.data photo.upload_date = util.the_time_now() photo.taken_date = taken_date photo.make = form.make.data photo.model = form.model.data photo.width = form.width.data photo.height = form.height.data photo.city = form.city.data photo.nation = form.nation.data photo.address = form.address.data photo.save() flash('Your file upload have been completed successfully!') return redirect( url_for("photoView.photos", form=form, gmaps_key=conf['GMAPS_KEY'])) except Exception as e: app.logger.error(e) util.delete(app, filename, current_user) return errorHandler.server_error(e) return render_template('upload.html', form=form, gmaps_key=conf['GMAPS_KEY'])
def photo_delete(photo_id): """ Delete specific file (with thumbnail) and delete DB record. :param photo_id: target photo id :return: Json data remove:fail or success """ app.logger.debug("Photo delete request: %s", photo_id) try: photo = Photo.get(current_user.id, photo_id) photo.delete() util.delete(app, photo.filename, current_user) flash('Successfully removed!') app.logger.debug('Successfully removed!') except Exception as e: app.logger.error(e) flash('Error occurred! Please try again.') return jsonify(remove='fail') return jsonify(remove='success')
def photo_delete(photo_id): """ Delete specific file (with thumbnail) and delete DB record. :param photo_id: target photo id :return: Json data remove:fail or success """ app.logger.debug("Photo delete request: %s", photo_id) try: photo = db.session.query(Photo).filter_by(id=photo_id).first() db.session.delete(photo) db.session.commit() util.delete(app, photo, current_user) flash('Successfully removed!') app.logger.debug('Successfully removed!') except Exception as e: app.logger.error(e) flash('Error occurred! Please try again.') return jsonify(remove='fail') return jsonify(remove='success')