def confirm_recipe_edit(userid, recipeid): """Make changes to the db to reflect the recipe edits.""" ####### Change Recipes Table ###### recipe_title = request.form.get("recipetitle") instructions = request.form.get("instructions") source = request.form.get("source") #update recipe table Recipe.edit_recipe(recipeid, recipe_title, instructions, source) ###### Change Tngredients Table ###### #delete old ingredients Ingredient.delete_old_recipe_ingredients(recipeid) #add new ingredients new_ingredient_count = Ingredient.get_ingredient_count(request.form) ingredients_dict = Ingredient.get_ingredients_to_add( new_ingredient_count, request.form) Ingredient.add_ingredient_to_recipe(new_ingredient_count, ingredients_dict, recipeid) ###### Change Hashtag Table ###### # no need to delete from hashtags table # just need to delete from the recipe_hashtags association table hashtags = request.form.get("hashtags") hashtag_list = re.sub('#', '', hashtags.lower()).split() # will add another row in hashtags table if a new hashtag # will get the hashtag_id if the hashtag already exists hashtag_id_list = Hashtag.get_hashtag_id(hashtag_list) ###### Recipe_Hashtag Table Section ###### #delete old recipe_hashtags Recipe_Hashtag.delete_old_recipe_hashtags(recipeid) # generate new recipe_hashtags Recipe_Hashtag.create_new_recipe_hashtag(recipeid, hashtag_id_list) ###### Tsvector Generation ###### Recipe.update_search_vector(recipeid) flash("You have successfully edited your recipe.", "edit_recipe") return redirect("/myrecipes/%d/recipe/%d" % (userid, recipeid))
def delete_recipe(userid, recipeid): """Delete recipe from the db.""" #delete old recipe_hashtags Recipe_Hashtag.delete_old_recipe_hashtags(recipeid) #delete old ingredients Ingredient.delete_old_recipe_ingredients(recipeid) #delete old recipe Recipe.delete_recipe(recipeid) #flash message flash("You have successfully deleted your recipe.", "delete_recipe") return redirect("/myrecipes/%d" % userid)
def confirm_recipe_edit(userid, recipeid): """Make changes to the db to reflect the recipe edits.""" ####### Change Recipes Table ###### recipe_title = request.form.get("recipetitle") instructions = request.form.get("instructions") source = request.form.get("source") #update recipe table Recipe.edit_recipe(recipeid, recipe_title, instructions, source) ###### Change Tngredients Table ###### #delete old ingredients Ingredient.delete_old_recipe_ingredients(recipeid) #add new ingredients new_ingredient_count = Ingredient.get_ingredient_count(request.form) ingredients_dict = Ingredient.get_ingredients_to_add(new_ingredient_count, request.form) Ingredient.add_ingredient_to_recipe(new_ingredient_count, ingredients_dict, recipeid) ###### Change Hashtag Table ###### # no need to delete from hashtags table # just need to delete from the recipe_hashtags association table hashtags = request.form.get("hashtags") hashtag_list = re.sub('#', '', hashtags.lower()).split() # will add another row in hashtags table if a new hashtag # will get the hashtag_id if the hashtag already exists hashtag_id_list = Hashtag.get_hashtag_id(hashtag_list) ###### Recipe_Hashtag Table Section ###### #delete old recipe_hashtags Recipe_Hashtag.delete_old_recipe_hashtags(recipeid) # generate new recipe_hashtags Recipe_Hashtag.create_new_recipe_hashtag(recipeid, hashtag_id_list) ###### Tsvector Generation ###### Recipe.update_search_vector(recipeid) flash("You have successfully edited your recipe.", "edit_recipe") return redirect("/myrecipes/%d/recipe/%d" % (userid, recipeid))