コード例 #1
0
ファイル: main.py プロジェクト: NguyenBaDat99/saleappv1
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)
コード例 #2
0
ファイル: main.py プロジェクト: nhatminh7599/saleappv1
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)
コード例 #3
0
ファイル: main.py プロジェクト: DoanDong123/saleappv1
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)
コード例 #4
0
ファイル: main.py プロジェクト: NguyenNgocHuy78/SaleApp
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)
コード例 #5
0
ファイル: main.py プロジェクト: NguyenBaDat99/saleappv1
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
コード例 #6
0
ファイル: main.py プロジェクト: tunguyen241lxa/saleappv1
def append_cate():
    return {"categories": dao.read_categories()}