Beispiel #1
0
def process_confirm_recipe_edit(recipeid):
    """Allows user to edit existing recipe and Save"""

    # get recipe object using recipeid
    recipe = Recipe.get_existing_recipe(recipeid)

    # get form variables and replace their value in the database for a given recipe
    recipe.recipe_id = recipeid
    recipe.title = request.form["title"]
    recipe.preparation = request.form["preparation"]
    recipe.yields = request.form["yields"]
    recipe.category_id = request.form["category_name"]
    recipe.image = request.form["image"]

    Ingredient.delete_existing_ingredients(recipeid)

    # get multiple ingredients information using getlist() method.
    ingredient_names = request.form.getlist('name')
    ingredient_quantities = request.form.getlist('quantity')
    ingredient_measures = request.form.getlist('measure')

    # iterate over range of ingredient_names and get user entered value for item, quantity and measure.
    for i in range(len(ingredient_names)):
        item = ingredient_names[i]
        quantity = ingredient_quantities[i]
        measure = ingredient_measures[i]
        Ingredient.create_ingredient(item=item, quantity=quantity, measure=measure, recipe_id=recipeid)

    db.session.commit()

    return redirect("/recipe-list")
Beispiel #2
0
def process_confirm_recipe_edit(recipeid):
    """Allows user to edit existing recipe and Save"""

    # get recipe object using recipeid
    recipe = Recipe.get_existing_recipe(recipeid)

    # get form variables and replace their value in the database for a given recipe
    recipe.recipe_id = recipeid
    recipe.title = request.form["title"]
    recipe.preparation = request.form["preparation"]
    recipe.yields = request.form["yields"]
    recipe.category_id = request.form["category_name"]
    recipe.image = request.form["image"]

    Ingredient.delete_existing_ingredients(recipeid)

    # get multiple ingredients information using getlist() method.
    ingredient_names = request.form.getlist('name')
    ingredient_quantities = request.form.getlist('quantity')
    ingredient_measures = request.form.getlist('measure')

    # iterate over range of ingredient_names and get user entered value for item, quantity and measure.
    for i in range(len(ingredient_names)):
        item = ingredient_names[i]
        quantity = ingredient_quantities[i]
        measure = ingredient_measures[i]
        Ingredient.create_ingredient(item=item,
                                     quantity=quantity,
                                     measure=measure,
                                     recipe_id=recipeid)

    db.session.commit()

    return redirect("/recipe-list")
Beispiel #3
0
def delete_recipe(recipeid):
    """deletes recipe for a given recipeid from database"""

    # Delete recipe when user clicks on a remove icon using model Class method
    Recipe.delete_existing_recipe(recipeid)

    Ingredient.delete_existing_ingredients(recipeid)

    flash("Your recipe has been deleted successfully")

    return redirect("/recipe-list")
Beispiel #4
0
def delete_recipe(recipeid):
    """deletes recipe for a given recipeid from database"""

    # Delete recipe when user clicks on a remove icon using model Class method
    Recipe.delete_existing_recipe(recipeid)

    Ingredient.delete_existing_ingredients(recipeid)

    flash("Your recipe has been deleted successfully")

    return redirect("/recipe-list")