def common_data(): q, s = utils.cart_stats() return { 'categories': dao.read_categories(), 'cart_quantity': q, 'cart_sum': s }
def add_or_update_product(): err = "" product_id = request.args.get("product_id") product = None if product_id: product = dao.read_product_by_id(product_id=int(product_id)) if request.method.lower() == "post": # name = request.form.get("name") # price = request.form.get("price", 0) # images = request.form.get("images") # description = request.form.get("description") # category_id = request.form.get("category_id", 0) # import pdb # pdb.set_trace() if product_id: # Cap nhat data = dict(request.form.copy()) data["product_id"] = product_id if dao.update_product(**data): return redirect(url_for("product_list")) else: # Them if dao.add_product(**dict(request.form)): return redirect(url_for("product_list")) err = "Something wrong!!! Please back later!" return render_template("product-add.html", categories=dao.read_categories(), product=product, err=err)
def add_or_update_products(): err = "" if request.method.lower() == "post": name = request.form.get("name") price = request.form.get("price", 0) images = request.form.get("images") description = request.form.get("description") category_id = request.form.get("category_id", 0) if (dao.add_product(name=name, price=price, images=images, description=description, category_id=category_id)): return redirect(url_for("list_products")) err = "Something wrong !!! Please back later!!!" return render_template("product-add.html", categories=dao.read_categories(), err=err)
def add_or_update_product(): err = "" product_id = request.args.get("product_id") product = None if product_id: product = dao.read_product_by_id(product_id=int(product_id)) if request.method.lower() == "post": if product_id: data = dict(request.form.copy()) data["product_id"] = product_id if dao.update_product(**data): return redirect(url_for("product_list")) else: if dao.add_product(**dict(request.form)): return redirect(url_for("product_list")) err = "Something wrong!!! Please back later!" return render_template("product-add.html", categories=dao.read_categories(), product=product, err=err)
def add_or_update_product(): product_id = request.args.get("product_id") product = None err = None if request.method == "POST": if product_id: data = dict(request.form.copy()) data["product_id"] = product_id if dao.update_products(**data): return redirect(url_for("product_list")) else: if dao.add_products(**dict(request.form)): return redirect(url_for("product_list")) err = "Đã xãy ra lỗi!!! Vui lòng kiểm tra lại" if product_id: product = dao.read_products_by_id(product_id=product_id) return render_template("product-add.html", categories=dao.read_categories(), product=product, err=err)
def index(): return render_template("index.html", categories=dao.read_categories())