コード例 #1
0
ファイル: catalog.py プロジェクト: dschieve/catalog
def ItemAdd():
    """
    Add Item - any user can add an item as long as they are logged in
    """
    if "username" not in login_session:
        loggedIn = False
        return redirect("/login")
    else:
        loggedIn = True

    categories = session.query(Category).all()
    if request.method == "POST":
        itemToAdd = Item()
        itemToAdd.item_name = request.form["item_name"]
        itemToAdd.item_description = request.form["item_description"]
        itemToAdd.category_id = request.form["category"]
        itemToAdd.user_id = login_session["user_id"]
        session.add(itemToAdd)
        session.commit()
        flash("Item Added")
        return redirect(url_for("HomePage"))
    else:
        return render_template("item_add.html", categories=categories, loggedIn=loggedIn)