def recipe_update(recipe_id): rToUpdate = Recipe.query.get(recipe_id) if rToUpdate.account_id != current_user.id: return login_manager.unauthorized() form = RecipeForm(request.form) form.name.data = rToUpdate.name form.ingredients.data = rToUpdate.ingredients form.recipetext.data = rToUpdate.recipe_text form.tips.data = rToUpdate.tips if request.method == "GET": return render_template("recipes/editrecipe.html", form=form, recipe=rToUpdate) if not form.validate(): return render_template("recipes/editrecipe.html", form=form) form = RecipeForm(request.form) rToUpdate.name = form.name.data rToUpdate.ingredients = form.ingredients.data rToUpdate.recipe_text = form.recipetext.data rToUpdate.tips = form.tips.data db.session().add(rToUpdate) db.session().commit() return redirect(url_for("recipes_index"))
def recipe_form(): if request.method == "GET": return render_template("/recipes/create.html", form = RecipeForm()) form = RecipeForm(request.form) if not form.validate: return render_template("/recipes/create.html", form = form) r = Recipe(form.name.data, form.instructions.data, form.diet.data, form.timeInMinutes.data) db.session().add(r) db.session().commit() return redirect(url_for("recipes_index"))
def recipes_save(recipe_id): form = RecipeForm(request.form) if not form.validate(): return render_template("recipes/form.html", form=form, form_action=url_for( "recipes_save", recipe_id=recipe_id), button_text="Save changes") recipe = Recipe.query.get(recipe_id) recipe.name = form.name.data.strip() recipe.servings = form.servings.data recipe.instructions = form.instructions.data ingredients = form.ingredients id_list = { ri_form.ingredient_id.data: ri_form.amount.data for ri_form in ingredients} ri_list = RecipeIngredient.query.filter_by(recipe_id=recipe_id).all() for ingredient in ri_list: if str(ingredient.ingredient_id) not in id_list: db.session.delete(ingredient) else: ingredient.amount = id_list.pop(str(ingredient.ingredient_id)) create_ingredients( [item for item in form.ingredients.data if item['ingredient_id'] in id_list], recipe.id) db.session.commit() return redirect(url_for("recipes_view", recipe_id=recipe.id))
def recipes_create(): form = RecipeForm(request.form) if not form.validate(): return render_template("recipes/form.html", form=form, form_action=url_for("recipes_create"), button_text="Create recipe") recipe = Recipe(form.name.data.strip()) recipe.servings = form.servings.data recipe.instructions = form.instructions.data recipe.account_id = current_user.id recipe.account_name = current_user.name ingredients = form.ingredients.data db.session().add(recipe) db.session().flush() new = create_ingredients(ingredients, recipe.id) db.session().commit() return redirect(url_for("recipes_view", recipe_id=recipe.id))
def recipe_create(): form = RecipeForm(request.form) ingredients = Ingredient.query.all() form.ingredients.choices = [(ingredient.ingredientid, ingredient.name) for ingredient in ingredients] r = Recipe(form.name.data, form.method.data, current_user.id) ingredient_ids = form.ingredients.data if not form.validate(): return render_template("recipes/new.html", form=form) db.session().add(r) db.session().commit() db.session.refresh(r) for id in ingredient_ids: i = Ingredient.query.get(id) r.recipeingredient.append(i) db.session().commit() return redirect(url_for("recipe_index"))
def recipes_create(): form = RecipeForm(request.form) form.recipe_id = -1 # Checking that the form passes validations if not form.validate(): return render_template("recipes/new.html", form=form) # Adding the new recipe name = form.name.data.strip() name = (name[0].upper() + name[1:]) newRecipe = Recipe(name) newRecipe.instruction = form.instruction.data newRecipe.preptime = form.preptime.data newRecipe.account_id = current_user.id # Separating and adding tags tagsString = form.tags.data.strip() tags = tagsString.split(',') Tag.add_tags(tags, newRecipe) # Commiting changes db.session().add(newRecipe) db.session().commit() # Ingredients need recipe ID, # so they are added only after the recipe is added addedRecipe = Recipe.query.filter(Recipe.name == newRecipe.name).first() ingredients = form.ingredients.data.splitlines() Ingredient.add_ingredients(ingredients, addedRecipe) return redirect(url_for("recipes_index"))
def recipe_show_one(recipe_id): recipe = Recipe.query.get(recipe_id) form = RecipeForm() form.id = recipe.id account = User.query.get(current_user.id) if recipe in account.favourites: form.favourite = True # reseptissä olevien raaka-aineiden oliot ingredients_in_recipe = IngredientInRecipe.query.filter( IngredientInRecipe.recipe == recipe.id).all() already_added = [] for i in ingredients_in_recipe: id_number = i.id amount = i.amount raw = Ingredient.query.get(i.ingredient) already_added.append({ 'id': id_number, 'amount': amount, 'ingredient': raw }) return render_template("recipes/recipe.html", recipe=recipe, form=form, already_added=already_added, ingredients_in_recipe=ingredients_in_recipe)
def recipe_edit(recipeid): try: recipe = Recipe.query.filter_by(id=recipeid).first() RecipeIngredient.query.filter_by(recipe_id=recipeid).delete() except: flash("Could not connect to database") return redirect(url_for("error_page", message="Error connecting to database")) form = RecipeForm().new() if request.method == "GET": form.name.data = recipe.name form.instruction.data = recipe.instruction return render_template("recipes/edit.html", recipeid=recipeid, form=form) if request.method == "POST" and form.validate(): recipe.name = form.name.data recipe.instruction = form.instruction.data for data in form.ingredients.data: ingredient = Ingredient.query.filter_by(name=data).first() recipe.ingredient.append(ingredient) try: db.session().commit() except: flash("Problems connecting to database") return redirect(url_for("error_page", message="Error connecting to database")) return redirect(url_for("recipes_index")) return render_template("recipes/edit.html", recipeid=recipeid, form=form)
def recipe_form(): ingredients = Ingredient.query.all() form = RecipeForm() form.ingredients.choices = [(ingredient.ingredientid, ingredient.name) for ingredient in ingredients] return render_template("recipes/new.html", form=form)
def recipe_editform(recipe_id): recipe = Recipe.query.get(recipe_id) form = RecipeForm() form.name.data = recipe.name form.description.data = recipe.description form.id = recipe.id account = User.query.get(current_user.id) if recipe in account.favourites: form.favourite = True return render_template("recipes/edit.html", form=form, recipe=recipe)
def recipes_create(): if request.method == "GET": return render_template("recipes/new.html", form=RecipeForm()) form = RecipeForm(request.form) if not form.validate(): return render_template("/recipes/new.html", form=form) url = uploadImage(form.image.name) r = Recipe(form.name.data, form.instructions.data, url) r.account_id = current_user.id db.session().add(r) db.session().flush() recipeId = r.id db.session().commit() return redirect(url_for("recipes_ingredients", recipeId=recipeId))
def recipes_edit(recipeId): if not recipeAuthorization(recipeId): return redirect(url_for("recipes_show")) recipe = Recipe.query.get(recipeId) form = RecipeForm() form.instructions.data = recipe.instructions form.name.data = recipe.name return render_template("recipes/edit.html", form=form, recipeId=recipeId)
def recipe_update(recipe_id): r = Recipe.query.get(recipe_id) form = RecipeForm(request.form) if not form.validate(): return render_template("recipes/edit.html/", form=form) r.name = form.name.data r.description = form.description.data db.session().commit() return redirect(url_for("recipes_index"))
def recipe_create(): form = RecipeForm(request.form) r = Recipe(form.name.data, form.description.data) r.creator = current_user.id if not form.validate(): return render_template("recipes/new.html", form=form) db.session().add(r) db.session().commit() return redirect(url_for("recipes_index"))
def recipes_editpage(recipe_id): r = Recipe.query.get(recipe_id) f = RecipeForm(obj=Recipe.query.get(recipe_id)) f2 = IngredientWithRecipeForm() f2.ingredient.choices = map( lambda i: (i.id, i.name + " ({})".format(i.unit)), Ingredient.query.order_by(Ingredient.name).all()) ings = map(lambda i: [i, r.get_quantity(r, i.id)], r.ingredients) return render_template("recipes/recipe.html", form=f, form2=f2, r=r, ingredients=ings)
def recipes_create(): form = RecipeForm(request.form) if not form.validate(): return render_template("recipes/new.html", form=form) recipe = Recipe(form.name.data) recipe.description = form.description.data recipe.content = form.content.data recipe.account_id = current_user.id db.session().add(recipe) db.session().commit() return redirect(url_for("recipes_index"))
def recipe_edit(recipe_id): r = Recipe.query.get(recipe_id) form = RecipeForm(formdata=request.form, obj=r) if r.account_id != current_user.id: if current_user.user_role == "ADMIN": pass else: return login_manager.unauthorized() if request.method == "POST": save_changes(r, form) return redirect(url_for("recipes_list")) return render_template("recipes/edit.html", recipe=r, form=form)
def recipes_create(): form = RecipeForm(request.form) if not form.validate(): return render_template("recipes/new.html", form=form) r = Recipe(form.name.data, form.text.data) r.difficult = form.difficult.data r.event = form.event.data r.account_id = current_user.id db.session().add(r) db.session().commit() return redirect(url_for("recipes_list"))
def recipes_create(): form = RecipeForm(request.form) if not form.validate(): return render_template("recipes/new.html", form=form) r = Recipe(form.name.data) r.favourite = form.favourite.data r.account_id = current_user.id r.description = cleanstr(form.description.data) db.session().add(r) db.session().commit() return redirect(url_for("recipes_index"))
def recipes_update(recipe_id): recipe = Recipe.query.get(recipe_id) if recipe.account_id != current_user.id: return login_manager.unauthorized() form = RecipeForm() if not form.validate(): return render_template("recipes/modify.html", form=form, recipe=recipe) recipe.name = form.name.data recipe.description = form.description.data recipe.content = form.content.data db.session.commit() return redirect(url_for("recipes_index"))
def recipes_edit(recipe_id): form = RecipeForm(request.form) r = Recipe.query.get(recipe_id) if not form.validate(): return redirect(url_for("recipes_view", recipe_id=recipe_id, form=form)) r.name = form.name.data r.favourite = form.favourite.data r.description = cleanstr(form.description.data) r.text = cleanstr(form.text.data) db.session().commit() return redirect(url_for("recipes_view", recipe_id=recipe_id))
def recipes_create(): form = RecipeForm(request.form) if not form.validate(): return render_template("recipes/new.html", form=form) nimi = form.nimi.data annoksia = form.annoksia.data aika = form.aika.data ohje = form.ohje.data r = Recipe(nimi, annoksia, aika, ohje) db.session().add(r) db.session().commit() return redirect(url_for("recipes_index"))
def recipes_save_edit(recipeId): form = RecipeForm(request.form) if not form.validate(): return render_template("/recipes/edit.html", form=form, recipeId=recipeId) recipe = Recipe.query.get(recipeId) recipe.image = uploadImage(form.image.name) or recipe.image recipe.name = form.name.data recipe.instructions = form.instructions.data db.session.commit() return redirect(url_for("recipes_ingredients", recipeId=recipeId))
def recipes_edit(recipe_id): recipe = Recipe.query.get(recipe_id) if recipe.account_id != current_user.id: abort(403) form = RecipeForm(obj=recipe) for ri_form in form.ingredients: ingredient = Ingredient.query.get(ri_form.ingredient_id.data) ri_form.ri_name.data = ingredient.name return render_template("recipes/form.html", form=form, form_action=url_for( "recipes_save", recipe_id=recipe.id), button_text="Save changes")
def recipe_edit_form(recipe_id): recipe = Recipe.query.get(recipe_id) if recipe.account_id != current_user.id: abort(403) form = RecipeForm() form.name.data = recipe.name form.duration.data = recipe.duration form.instructions.data = recipe.instructions form.course.data = next(tag for tag in recipe.tags if tag.category == "course").name form.dairy_free.data = any(tag.name == "Dairy-Free" for tag in recipe.tags) form.gluten_free.data = any(tag.name == "Gluten-Free" for tag in recipe.tags) form.vegan.data = any(tag.name == "Vegan" for tag in recipe.tags) return render_template("recipes/edit.html", form=form, recipe_id=recipe_id)
def recipes_create(): form = RecipeForm(request.form) if not form.validate(): return render_template("recipes/new.html", form=form) name = form.name.data duration = form.duration.data instructions = form.instructions.data recipe = Recipe(name, duration, instructions) recipe.account_id = current_user.id recipe.tags = get_tags(form) db.session().add(recipe) db.session().commit() return redirect(url_for("recipes_index"))
def recipes_create(): form = RecipeForm(request.form) if not form.validate(): return render_template("recipes/new.html", form=form) r = db.session.query(Recipe).filter( Recipe.name == form.name.data).one_or_none() if r is not None: flash("Recipe you are trying to add already exists", "warning") elif form.name.data.__len__() < 2: flash("Recipe name has to be longer than 1 character", "warning") else: flash("Recipe has been added", "success") t = Recipe(form.name.data) t.account_id = current_user.id db.session().add(t) ingredients_string = form.ingredientString.data ingredients = [x.strip() for x in ingredients_string.split(',')] for ingredient in ingredients: x = db.session.query(Ingredient).filter( Ingredient.name == ingredient).one_or_none() if not x: if ingredient.__len__() < 2: flash("Ingredient name has to be longer than 1 character", "warning") else: x = Ingredient(ingredient) x.account_id = current_user.id db.session().add(x) t.recipeIngredients.append(x) try: db.session().commit() except Exception as e: print(str(e)) return redirect(url_for("recipes_create"))
def recipes_create(): form = RecipeForm(request.form) form.ingredients.choices = [(ingredient.id, ingredient.name) for ingredient in Ingredient.query.all()] if not form.validate(): return render_template("recipes/new.html", form=form) ingredients = [Ingredient.query.get(id) for id in form.ingredients.data] r = Recipe(form.name.data, form.text.data) r.difficult = form.difficult.data r.event = form.event.data r.account_id = current_user.id r.recipeingredients = ingredients db.session().add(r) db.session().commit() return redirect(url_for("recipes_list"))
def recipe_create(): form = RecipeForm(request.form) if not form.validate(): return render_template("recipes/newrecipe.html", form=form) newrecipe = Recipe(form.name.data, form.ingredients.data, form.recipetext.data, form.tips.data) newrecipe.account_id = current_user.id db.session().add(newrecipe) db.session.commit() for category in form.categories.data: newrecipecategory = RecipeCategory(newrecipe.id, category.id) db.session.add(newrecipecategory) db.session.commit() return redirect(url_for("recipes_index"))
def recipes_create(): form = RecipeForm().new() if request.method == "GET": return render_template("recipes/new.html", form=form) if request.method == "POST" and form.validate(): try: r = Recipe(form.name.data, form.instruction.data) r.account.append(current_user) for data in form.ingredients.data: ingredient = Ingredient.query.filter_by(name=data).first() r.ingredient.append(ingredient) db.session().add(r) db.session().commit() return redirect(url_for("recipes_index")) except: flash("could not connect to database") return redirect(url_for("error_page", message="Error connecting to database")) return render_template("recipes/new.html", form=form)