def step_impl(context): for row in context.table: try: Product.get(Product.name == row['name']) except Product.DoesNotExist: Product.create(name=row['name'], price=row['price'], category_id=row['category_id'])
def step_1(context): for row in context.table: try: Product.get(Product.name == row['name']) except Product.DoesNotExist: Product.create(name=row['name'], price=row['price'], description=row['description'])
def add(self, nombre, proveedor, categoria, precio, existencias): product = Product() product.name_product = nombre result = product.read() if result: return -1 else: product.provider = proveedor product.category = categoria product.unit_price = precio product.stock = existencias product.create() return product
def post(self): args = self.reqparse.parse_args() # with DB.atomic(): filtered_args = {k: v for k, v in args.items() if v is not None} args.clear() args.update(filtered_args) product = Product.create(**args) return {'isSuccess': True, 'product_id': product.product_id}
def saveProductInDatabase(): data = request.form split_category = data['category'].split("-") id_category = int(split_category[0]) category_name = split_category[1].lower() image_name = _save_image(request.files['image'], category_name) if image_name is None: return redirect(url_for('.addProduct')) else: producto = Product(-1, id_category, data['product_name'], data['price'], "images/" + category_name + "/" + image_name, 0) print(producto) if producto.create(connection): return redirect('/admin/panel') else: flash("Error while executing command to database") return redirect(url_for('.addProduct'))
def create(): # A: Check if there is file in form if "user_file" not in request.files: return "No user_file key in request.files" # B file = request.files["user_file"] # print(file) # C. if file.filename == "": return "Please select a file" # D. if file and allowed_file(file.filename): # Ensure correct orientation img = PILImage.open(file) #Create a Pillow file object if hasattr(img, '_getexif'): exifdata = img._getexif() try: orientation = exifdata.get(274) print(orientation) if orientation==6: img = img.rotate(-90) else: pass except: pass # orientation = 1 fs = BytesIO() # Save image with Pillow into FileStorage object. img.save(fs, format='JPEG') file.filename = secure_filename(file.filename) output = upload_file_to_s3(fs, file.filename, app.config["S3_BUCKET"], file.mimetype) name = request.form['name'] description = request.form['description'] category = request.form['category'] price = request.form['price'] product_url=request.form['product_url'] clarifai_id=request.form['clarifai_id'] concept = request.form['concept'] product = Product.create(image_url=str(file.filename), name=name, description=description, category=category, price=price, concept=concept, seller_id=current_user.id, product_url=product_url, clarifai_id=clarifai_id) product.save() flash("Image uploaded") id=current_user.id return redirect(url_for('sellers.show', id=id)) else: id=current_user.id return redirect(url_for('sellers.show', id=id))
def get(self, category_id): with DB.atomic(): product = Product.create(name='product 1 + %s' % random.random(), price='5', category_id=category_id) return {'isSuccess': True, 'product_id': product.product_id}