예제 #1
0
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)
예제 #2
0
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)