Exemple #1
0
def delete_food():
    if request.method == "GET":
        return render_template("deletefood.html")
    elif request.method == "POST":
        new_food = FoodItem.objects(title=request.form["title"]).first()
        new_food.delete()
        return render_template("deletefood.html")
Exemple #2
0
def add_food():
    if request.method == "GET":
        return render_template("addfood.html")
    elif request.method == "POST":
        file = request.files['source']
        if file:
            filename = secure_filename(file.filename)
            if os.path.exists(os.path.join(app.config['UPLOAD_PATH'],
                                           filename)):
                name_index = 0
                original_name = filename.rsplit('.', 1)[0]
                original_extension = filename.rsplit('.', 1)[1]
                while os.path.exists(
                        os.path.join(app.config['UPLOAD_PATH'], filename)):
                    name_index += 1
                    filename = "{0} ({1}).{2}".format(original_name,
                                                      name_index,
                                                      original_extension)
            file.save(os.path.join(app.config['UPLOAD_PATH'], filename))
            new_food = FoodItem()
            new_food.src = url_for('uploaded_file', filename=filename)
            new_food.title = request.form["title"]
            new_food.description = request.form["description"]
            new_food.save()
            return render_template("addfood.html")
Exemple #3
0
def update_food():
    if request.method == "GET":
        return render_template("updatefood.html")
    elif request.method == "POST":
        new_food = FoodItem.objects(title=request.form["title_old"]).first()
        if new_food is not None:
            new_food.delete()
            new_food = FoodItem()
            new_food.src = request.form["source"]
            new_food.title = request.form["title"]
            new_food.description = request.form["description"]
            new_food.save()
        return render_template("updatefood.html")
Exemple #4
0
def add_food():
    if request.method == "GET":
        return render_template("addfood.html")
    elif request.method == "POST":
        new_food = FoodItem()
        new_food.src = request.form["source"]
        new_food.title = request.form["title"]
        new_food.description = request.form["description"]
        new_food.save()
        return render_template("addfood.html")
Exemple #5
0
def foodblog1():
    return render_template("foodblog1.html", food_list=FoodItem.objects())