def delete_account(user_id): user = User.get_by_id(user_id) User.delete_user(user_id) images = Image.images_from_mongo(user.username) Image.delete_images(user.username) # delete images from folder for image in images: target = os.path.join(APP_ROOT, 'static/images/{}'.format(image.filename)) os.remove(target) # delete the profile_pic as well if user.profile_image != 'Anonyymi.jpeg': target2 = os.path.join( APP_ROOT, "static/profile_pics/{}".format(user.profile_image)) os.remove(target2) # log out session.clear() logout_user() flash('Your account and all images associated with it are now deleted', "success") return render_template("home.html", images=all_images())
def create(): message = { "success": False, } if request.method == 'POST': form_data = json.loads(request.form.get('form')) # update or create new print(form_data) new_restaurant = Restaurant(name=form_data["name"], hotline=form_data["hotline"], address=form_data["address"], description=form_data["description"], user_id=current_user.id) db.session.add(new_restaurant) try: db.session.commit() img = Image(url=form_data["img_logo_url"]) db.session.add(img) db.session.commit() new_restaurant.image_id = img.id db.session.commit() except SQLAlchemyError as e: db.session.rollback() message['success'] = True message['restaurant'] = new_restaurant.id return jsonify(message)
def delete_image(image_id): image = Image.get_by_id(image_id) image.delete_image() # to save memory we should delete the actual image file as well target = os.path.join(APP_ROOT, "static/images/{}".format(image.filename)) os.remove(target) return render_template( "gallery.html", images=Image.images_from_mongo(current_user.username), profile_pic=url_for('static', filename='profile_pics/{}'.format( current_user.profile_image)))
def upload_images(): form = PostForm() if form.validate_on_submit(): img = form.picture.data filename = img.filename caption = form.caption.data # verify the file type, we want to save only jpg, jpeg and png files extension = os.path.splitext(filename)[1].lower() if (extension != '.jpg') and (extension != '.png') and (extension != '.jpeg'): flash('You can upload only .jpg, .jpeg and .png files', 'danger') return redirect(url_for('upload_images')) # if image was stored in the database (return value was True) # then we will save the image in specified location if Image.new_image(current_user.username, caption, filename, current_user.profile_image): target = os.path.join(APP_ROOT, "static/images", filename) img.save(target) flash('Image posted.', 'success') return render_template('home.html', images=all_images()) #filename was already in the current user directory else: flash('Image is already posted by you.', 'danger') return render_template('upload_image.html', form=form, legend='New Post')
def get_face_locations(img: Image): digest = img.get_digest() face_locations = fr.face_locations(digest) locs = [] for location in face_locations: top, right, bottom, left = location locs.append([ int(top / img.ratio), int(right / img.ratio), int(bottom / img.ratio), int(left / img.ratio), ]) return locs
def show_images(): # returns a list of image objects for given username images = Image.images_from_mongo(current_user.username) images.reverse() profile_pic = url_for('static', filename='profile_pics/{}'.format( current_user.profile_image)) return render_template("gallery.html", images=images, profile_pic=profile_pic)
def load_images_in_path(breed: str, path: str) -> List[Image]: """ Takes a path and loads all image files from it :param path: A full path to load from :return: A list of Image objects """ images = [] all_files_in_path = listdir(path) for file in all_files_in_path: image_full_path = join(path, file) if is_image_file(image_full_path): images.append( Image(image_path=image_full_path, image_id=file, image_classification=breed)) return images
def update(id): message = { "success": False, } if request.method == 'POST': form_data = json.loads(request.form.get('form')) # update or create new restaurant = Restaurant.query.filter_by(id=id).first() restaurant.name = form_data["name"] restaurant.hotline = form_data["hotline"] restaurant.address = form_data["address"] restaurant.description = form_data["description"] img = Image(name=form_data["img_logo_url"]) db.session.add(img) db.session.commit() restaurant.image_id = img.id db.session.commit() message["success"] = True return
def createDish(): message = { "success": False, } if request.method == 'POST': form_data = json.loads(request.form.get('form')) # update or create new print(form_data["optionsSeleted"]) new_dish = Dish(name=form_data["name"], showname=form_data["showname"], description=form_data["description"], price=form_data["price"], category_id=form_data["category"], restaurant_id=form_data["restaurant_id"]) # add category id and restaurant id db.session.add(new_dish) for option_id in form_data["optionsSeleted"]: optionObj = Option.query.filter_by(id=option_id).first() new_dish.selection.append(optionObj) try: db.session.commit() img = Image(url=form_data["img_logo_url"]) db.session.add(img) db.session.commit() new_dish.image_id = img.id db.session.commit() db.session.commit() except SQLAlchemyError as e: db.session.rollback() message['success'] = True message['restaurant'] = new_dish.id return jsonify(message)
def all_images(): images = Image.all_images() images.reverse() return images
def image(image_id): image = Image.get_by_id(image_id) return render_template("image.html", image=image)
def images(image_id): image = Image.get_by_id(image_id) fr = make_response(image.get_data()) fr.headers['Content-Type'] = image.get_content_type() return fr
def upload_image(): file_data = request.files['file'] image = Image(file_data.read(), file_data.mimetype) image.save_to_db() return jsonify({"id": image.get_id()}), 200
def load_from_path(path): img_arr = cv2.imread(path) return Image(img_arr)