Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 3
0
def process_recipe_form():
    """Process recipe form to add new recipe to the database."""

    print "request.form: ", request.form

    # get recipe form variables.
    userid = session["user_id"]
    title = request.form["title"]
    preparation = request.form["preparation"]
    yields = request.form["yields"]
    category_id = request.form["category_name"]
    image = request.form["image"]

    # 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')

    # add above recipe information to database using create_recipe() method from model Class Recipe.
    new_recipe = Recipe.create_recipe(title, category_id, userid, preparation,
                                      yields, image)

    # get recipe id using get_recipe_id() method from model Class Recipe.
    # recipe_id = Recipe.get_recipe_id(title, userid) # this is a bug, don't use this line.

    recipe_id = new_recipe.recipe_id

    # 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]

        #add ingredient information to database using create_ingredient() method from model Class Ingredient.
        Ingredient.create_ingredient(item=item,
                                     quantity=quantity,
                                     measure=measure,
                                     recipe_id=recipe_id)

    return redirect("/recipe-list")
Ejemplo n.º 4
0
def process_recipe_form():
    """Process recipe form to add new recipe to the database."""

    print "request.form: ", request.form

    # get recipe form variables.
    userid = session["user_id"]
    title = request.form["title"]
    preparation = request.form["preparation"]
    yields = request.form["yields"]
    category_id = request.form["category_name"]
    image = request.form["image"]

    # 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')

    # add above recipe information to database using create_recipe() method from model Class Recipe.
    new_recipe = Recipe.create_recipe(title, category_id, userid, preparation, yields, image)

    # get recipe id using get_recipe_id() method from model Class Recipe.
    # recipe_id = Recipe.get_recipe_id(title, userid) # this is a bug, don't use this line.

    recipe_id = new_recipe.recipe_id

    # 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]

        #add ingredient information to database using create_ingredient() method from model Class Ingredient.
        Ingredient.create_ingredient(item=item,
                                     quantity=quantity,
                                     measure=measure,
                                     recipe_id=recipe_id)

    return redirect("/recipe-list")