Beispiel #1
0
    def toggle_reaction(self, recipe_id, refresh=False):
        recipe = Recipe.load(recipe_id)
        recipe.toggle_reaction()

        # TODO: This should be made without turbo, but problem with Bootstrap table
        if turbo.can_stream() and not refresh:
            return turbo.stream(
                turbo.replace(
                    template("public_recipes/_recipe_row.html.j2",
                             recipe=recipe),
                    target=f"recipe-{recipe_id}",
                ))

        return redirect(request.referrer)
Beispiel #2
0
    def post(self, recipe_id):
        from app.controllers import EditRecipeIngredientView

        recipe = Recipe.load(recipe_id)

        form = IngredientForm(request.form)

        ingredient = Ingredient()
        form.populate_obj(ingredient)
        ingredient.save()

        recipe.add_ingredient(ingredient)

        ingredient.set_additional_info(recipe)

        if turbo.can_stream():
            return turbo.stream([
                turbo.remove(target="add-ingredient-simple"),
                turbo.prepend(
                    self.template(
                        template_name="recipes/edit/ingredient/_row.html.j2",
                        ingredient=ingredient,
                        recipe=recipe,
                        editing=True,
                    ),
                    target="ingredients",
                ),
                turbo.after(
                    self.template(
                        template_name="recipes/edit/ingredient/_edit.html.j2",
                        ingredient=ingredient,
                        recipe=recipe,
                    ),
                    target=f"ingredient-{ingredient.id}",
                ),
            ] + EditRecipeIngredientView().update_usable_ingredients(recipe))
        else:
            return redirect(url_for("RecipeView:edit", id=recipe_id))
Beispiel #3
0
 def before_request(self, name, id=None, **kwargs):
     self.recipe = Recipe.load(id)
Beispiel #4
0
 def toggle_reaction_AJAX(self):
     recipe = Recipe.load(request.json["recipe_id"])
     recipe.toggle_reaction()
     return jsonify(recipe.has_reaction)
Beispiel #5
0
 def before_add_recipe(self, daily_plan_id):
     self.daily_plan = DailyPlan.load(daily_plan_id)
     self.recipe = Recipe.load(request.form["recipe_id"])
     if not self.recipe.can_current_user_add:
         abort(403)
Beispiel #6
0
 def before_request(self, name, recipe_id, **kwargs):
     self.recipe = Recipe.load(recipe_id)
     self.validate_edit(self.recipe)
Beispiel #7
0
    def before_request(self, name, id=None, **kwargs):
        self.recipe = Recipe.load(id)

        if current_user.is_authenticated and self.recipe:
            self.validate_show(self.recipe)