Example #1
0
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))
Example #2
0
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))
Example #3
0
def add_new_recipe():
    """Add new recipe to the database."""

    try:
        ###### Recipe Table Section ######
        user_id = session['User']
        recipe_title = request.form.get("recipetitle")
        instructions = request.form.get("instructions")
        source = request.form.get("recipesource")

        new_recipe = Recipe.create_new_recipe(user_id, recipe_title,
                                              instructions, source)
        recipe_id = new_recipe.recipe_id

        ###### Ingredient Table Section ######
        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, recipe_id)

        ###### Hashtag Table Section ######
        hashtags = request.form.get("hashtags")

        # stardardizes format for hashtags
        hashtag_list = re.sub('#', '', hashtags.lower()).split()

        hashtag_id_list = Hashtag.get_hashtag_id(hashtag_list)

        ###### Recipe_Hashtag Table Section ######
        Recipe_Hashtag.create_new_recipe_hashtag(recipe_id, hashtag_id_list)

        ###### Tsvector Generation ######
        Recipe.update_search_vector(recipe_id)

        flash("You have successfully created your recipe. Hooray!",
              "create_recipe")

        return redirect("/myrecipes/%d" % user_id)

    except Exception:

        return redirect("/")
Example #4
0
def add_new_recipe():
    """Add new recipe to the database."""

    try:
        ###### Recipe Table Section ######
        user_id = session['User']
        recipe_title = request.form.get("recipetitle")
        instructions = request.form.get("instructions")
        source = request.form.get("recipesource")

        new_recipe = Recipe.create_new_recipe(user_id, recipe_title, instructions, source)
        recipe_id = new_recipe.recipe_id

        ###### Ingredient Table Section ######
        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, recipe_id)

        ###### Hashtag Table Section ######
        hashtags = request.form.get("hashtags")

        # stardardizes format for hashtags
        hashtag_list = re.sub('#', '', hashtags.lower()).split()

        hashtag_id_list = Hashtag.get_hashtag_id(hashtag_list)

        ###### Recipe_Hashtag Table Section ######
        Recipe_Hashtag.create_new_recipe_hashtag(recipe_id, hashtag_id_list)

        ###### Tsvector Generation ######
        Recipe.update_search_vector(recipe_id)

        flash("You have successfully created your recipe. Hooray!", "create_recipe")

        return redirect("/myrecipes/%d" % user_id)

    except Exception:

        return redirect("/")