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")
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")
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")
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")
def foodblog1(): return render_template("foodblog1.html", food_list=FoodItem.objects())