Exemplo n.º 1
0
def main():
    kw = request.args.get("keyword")

    if kw:
        return render_template("lookUp.html",
                               product_1=dao.read_products(keyword=kw))
    else:
        return render_template("main.html", product_1=dao.read_products())
Exemplo n.º 2
0
def api_product_list():
    if request.method == "POST":
        err = ""
        product_id = request.args.get("product_id")
        product = None
        if product_id:
            product = dao.read_product_id(product_id=int(product_id))

        if request.method.lower() == "post":
            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

                import json
                product = dao.add_product(**dict(json.loads(request.data)))
                if product:
                    return jsonify(product)

            err = "Something wrong!!! Please back later!"

        return jsonify({"error_message": err})

    kw = request.args.get("keyword")

    return jsonify(dao.read_products(keyword=kw))
Exemplo n.º 3
0
def product_list():
    kw = request.args.get("keyword", None)
    from_price = request.args.get("from_price")
    to_price = request.args.get("to_price")
    return render_template("products.html",
                           products=dao.read_products(keyword=kw,
                                                      from_price=from_price,
                                                      to_price=to_price))
Exemplo n.º 4
0
def export_csv():
    products = dao.read_products()
    p = os.path.join(app.root_path, "data/products-%s.csv" % str(datetime.now()))
    with open(p, "w", encoding="utf-8") as f:
        writer = csv.DictWriter(f, fieldnames=["id", "name", "description",
                                               "price", "images", "category_id"])
        writer.writeheader()
        for product in products:
            writer.writerow(product)

    return p
Exemplo n.º 5
0
def products_list():
    # kw = request.args("keyword")
    # how difference? neu co truyen keyword thi lay len con ko thi se lay None
    # => khong bi loi
    kw = request.args.get("keyword")
    from_price = request.args.get("from_price")
    to_price = request.args.get("to_price")

    return render_template("products.html",
                           products=dao.read_products(keyword=kw,
                                                      from_price=from_price,
                                                      to_price=to_price))
Exemplo n.º 6
0
def laptop():
    # products = dao.read_products()
    err = ''
    if request.method == 'POST':
        kw = request.form.get("kw")
        price = request.form.get("search_price")
        # brand = request.form.get("search_brand")
        # print(brand)

        if price == "Dưới 10 triệu":
            from_price = 1.0
            to_price = 10000000.0
        elif price == "Từ 10 - 20 triệu":
            from_price = 10000000.0
            to_price = 20000000.0
        elif price == "Trên 20 triệu":
            from_price = 20000000.0
            to_price = 100000000.0
        elif price == "Tất cả":
            from_price = 0.0
            to_price = 100000000.0

        products = dao.read_products(name=kw,
                                     from_price=from_price,
                                     to_price=to_price)
        print(products)
        if products == []:
            err = "Sản phẩm không tồn tại!"
            return render_template("laptop.html",
                                   products=dao.read_all_products(),
                                   err=err)
        else:
            msg = 'Kết quả tìm kiếm ' + " '" + kw + "'" + " , " + price
            return render_template("laptop.html", products=products, msg=msg)

    return render_template("laptop.html", products=dao.read_all_products())
Exemplo n.º 7
0
def product_by_category(category_id):
    return render_template("products.html",
                           products=dao.read_products(category_id=category_id))
Exemplo n.º 8
0
def product_list():
    return render_template("products.html", products=dao.read_products())
Exemplo n.º 9
0
def index():
    return render_template("index.html",
                           latest_products=dao.read_products(latest=True))
Exemplo n.º 10
0
def index():
    products = dao.read_products()

    return render_template("index.html", products=products)
Exemplo n.º 11
0
def bookList():
    return render_template("book-list.html", product_1=dao.read_products())
Exemplo n.º 12
0
def bookDetail():
    return render_template("book-detail.html", product_1=dao.read_products())
Exemplo n.º 13
0
def books():
    return render_template("books.html", product_1=dao.read_products())
Exemplo n.º 14
0
def admin():
    if current_user.is_authenticated:
        return render_template("admin/index.html",
                               product_1=dao.read_products())
    else:
        return render_template("main.html")
Exemplo n.º 15
0
def product_list():
    return render_template("products.html",
        products=dao.read_products(**dict(request.args)))