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