Ejemplo n.º 1
0
def delete_item(item_id, category_id):
    if request.method == "GET":
        databaseManager = DatabaseManager()
        item = databaseManager.get_item(item_id)
        return render_template("delete_item.html",
                               item=item,
                               category_id=category_id)
    else:
        flash("delete item successfully")
        databaseManager = DatabaseManager()
        databaseManager.delete_item(item_id)
        if category_id == 0:
            return redirect(url_for("show_latest_catalog"))
        else:
            return redirect(url_for("show_catalog", id=category_id))
Ejemplo n.º 2
0
def edit_item(item_id, category_id):
    databaseManager = DatabaseManager()
    if request.method == "GET":
        item = databaseManager.get_item(item_id)
        categories = databaseManager.get_categories()
        return render_template("edit_item.html",
                               item=item,
                               categories=categories,
                               category_id=category_id)
    else:
        item = databaseManager.update_item(item_id, request.form["name"],
                                           request.form["description"],
                                           request.form["category"])
        flash("update item successfully")
        if category_id == 0:
            return redirect(url_for("show_latest_catalog"))
        else:
            return redirect(url_for("show_catalog", id=item.category_id))
Ejemplo n.º 3
0
def show_item(item_id, category_id):
    databaseManager = DatabaseManager()
    item = databaseManager.get_item(item_id)
    return render_template("show_item.html",
                           item=item,
                           category_id=category_id)
Ejemplo n.º 4
0
def get_items_by_id(item_id):
    databaseManager = DatabaseManager()
    item = databaseManager.get_item(item_id)
    return jsonify(item.serialize)