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 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 add_product_to_db(product: dict) -> None: """Takes a dictionary and inserts the product into the db. If a product with duplicate name is found, existing data will be updated if the 'date_updated' is higher than the existing record. Parameters ---------- product : dict Row of Product data Returns ------- None """ try: Product.insert( product_name=product["product_name"], product_price=product["product_price"], product_quantity=product["product_quantity"], date_updated=product["date_updated"], ).execute() except IntegrityError: result = Product.get(product_name=product["product_name"]) if product["date_updated"] >= result.date_updated: result.product_quantity = product["product_quantity"] result.product_price = product["product_price"] result.date_updated = product["date_updated"] result.save()
def initialize(self): super().initialize() if self.user_id is not None: self.user = User.get(id=self.user_id) if self.product_ids is not None: self.products = [ Product.get(id=product_id) for product_id in self.product_ids ]
def productreport(): if request.method == 'POST': # do stuff when the form is submitted # redirect to end the POST handling # the redirect can be to the same route or somewhere else category = request.form.get('category') startDate = request.form.get("startDatePicker") endDate = request.form.get("endDatePicker") #print(f" {startDatePicker}") productlist = Product.get(category, startDate, endDate) return render_template('queryproducts.html', productlist=productlist) categories = mongo.db.categories.find({}) categoryList = set([x["categories"][0] for x in categories]) return render_template('productreport.html', categories=categoryList)
def productlist(categoryname): productlist = Product.get(categoryname, None, None) return render_template("products.html", productlist=productlist)
async def start(self) -> List[Entry]: self.log.info(f"product_id: {self.product_id}") product = Product.get(id=self.product_id) return self.respond(data=self.Response(result=product))