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 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 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)