Ejemplo n.º 1
0
def delete_food(id):
    delete_food = Foods.find_one({"_id": ObjectId(id)})
    if delete_food is not None:
        Foods.delete_one(delete_food)
    else:
        return "Not found"
    return redirect("/foods")
Ejemplo n.º 2
0
def add_food():
    if request.method == "GET":
        return render_template("add_food.html")
    elif request.method == "POST":
        form = request.form
        new_foods = {
            "title": form["title"],
            "description": form["desc"],
            "link": form["img_link"],
            "type": form["food_type"]
        }
        Foods.insert_one(new_foods)
        return redirect("/foods")
Ejemplo n.º 3
0
def edit_food(id):
        e = Foods.find_one({"_id": ObjectId(id)})
        if request.method == "GET":
                return render_template("edit_food.html",E = e)
        elif request.method == "POST":
                form = request.form
                new_food ={ "$set": {
                        "title": form["title"],
                        "description": form["description"],
                        "link": form["link"],
                        "type": form["type"],
                }}
                Foods.update_one(e, new_food)
                return redirect("/foods")
Ejemplo n.º 4
0
def edit_food(id):
    edit_food = Foods.find_one({"_id": ObjectId(id)})
    if request.method == "GET":
        return render_template("edit_food.html", EDIT_FOOD=edit_food)
    elif request.method == "POST":
        form = request.form
        new_food_info = {
            "title": form["title"],
            "description": form["desc"],
            "link": form["img_link"],
            "type": form["food_type"],
        }
        new_value = {"$set": new_food_info}
        Foods.update_one(edit_food, new_value)
        return redirect('/foods')
Ejemplo n.º 5
0
def add_food():
    if request.method == "GET":
        return render_template("add_food.html")
    elif request.method == "POST":
        form = request.form
        title = form["title"]
        description = form["desc"]
        link = form["img_link"]
        food_type = form["food_type"]
        new_food = {
            "title": title,
            "description": description,
            "link": link,
            "type": food_type,
        }
        Foods.insert_one(new_food)
        return redirect("/foods")
Ejemplo n.º 6
0
def home():
    if "logged" in session:
        if session["logged"]:
            all_foods = Foods.find()
            return render_template("all_food.html", ALL_FOODS=all_foods)
        else:
            return redirect("/login")
    else:
        return redirect("/login")
Ejemplo n.º 7
0
def home():
    all_foods = Foods.find()
    return render_template("all_food.html", ALL_FOODS=all_foods)
Ejemplo n.º 8
0
def food_detail(id):
    food = Foods.find_one({"_id": ObjectId(id)})
    return render_template("food_detail.html", FOOD=food)
Ejemplo n.º 9
0
def delete_food(id):
        delete = Foods.find_one({"_id": ObjectId(id)})
        Foods.delete_one(delete)
        return redirect("/foods")