def add_product(): """ add: /products/add update: /products/add?product_id :return: template """ err_msg = None if request.method.lower() == "post": if request.args.get("product_id"): # UPDATE d = dict(request.form.copy()) d["product_id"] = request.args["product_id"] if dao.update_product(**d): return redirect( url_for('product_list', product_id=d["product_id"])) else: err_msg = "Something wrong, go back later!!!" else: # ADD if dao.add_product(**dict(request.form)): return redirect(url_for('product_list')) else: err_msg = "Something wrong, go back later!!!" categories = dao.read_categories() product = None if request.args.get("product_id"): product = dao.read_product_by_id( product_id=int(request.args["product_id"])) return render_template("product-add.html", categories=categories, product=product, err_msg=err_msg)
def product_add(): err_msg = None if request.method == "POST": if request.args["product_id"] and int(request.args["product_id"]) > 0: p = dict(request.form.copy()) p["id"] = request.args["product_id"] if dao.product_update(**p): return redirect(url_for('product_list')) else: pass else: if dao.product_add(**dict(request.form)): return redirect(url_for('product_list')) else: err_msg = "something wrong" product = None if request.args["product_id"]: if int(request.args["product_id"]) > 0: product = dao.read_product_by_id(int(request.args["product_id"])) categories = dao.read_categories() return render_template("product-add.html", categories=categories, err_msg=err_msg, product=product)
def product_add(): err_msg = None if request.method.lower() == "post": if request.args.get("product_id"): # Update d = dict(request.form.copy()) d["product_id"] = int(request.args["product_id"]) if dao.update_product(**d): return redirect(url_for('product_list')) else: err_msg = "Somthing wrong" else: # ADD if dao.add_products(**dict(request.form)): return redirect(url_for('product_list')) else: err_msg = "Somthing wrong" categories = dao.read_categories() product = None if request.args["product_id"]: product = dao.read_product_by_id(int(request.args["product_id"])) return render_template("product-add.html", categories=categories, product=product, err_msg=err_msg)
def product_add(): err_msg = None if request.method.lower() == "post": if dao.add_products(**dict(request.form)): return redirect(url_for('product-add.html')) else: err_msg = "Wrong!" categories = dao.read_categories() product = None if request.args.get("product_id"): product = dao.read_product_by_id(product_id=request.args("product_id")) return redirect(url_for('product-add.html')) categories = dao.read_categories() return render_template("product-add.html", categories=categories)
def append_cate(): common = {"categories": dao.read_categories()} if 'cart' in session and session['cart']: q = 0 s = 0 for c in list(session["cart"].values()): q = q + c['quantity'] s = s + c['quantity'] * c['price'] common['cart_quantity'] = q common['cart_price'] = s return common
def append_cate(): return {"categories": dao.read_categories()}