Пример #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))
Пример #2
0
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)
Пример #3
0
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)
Пример #4
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))
Пример #5
0
def edit_recipe(userid, recipeid):
    """Get a recipe from the db, and display it so the user can edit."""

    recipe = Recipe.get_recipe(recipeid)

    ingredients = Ingredient.get_recipe_ingredients(recipeid)

    recipe_hashtags = Recipe_Hashtag.get_recipe_hashtags(recipeid)

    hashtag_list = Recipe_Hashtag.get_hashtag_names_for_recipe(recipe_hashtags)

    readable_hashtags = Hashtag.get_readable_hashtags(hashtag_list)

    recreated_hashtag_input = Hashtag.recreate_hashtag_input(readable_hashtags)

    return render_template("edit_recipe.html", recipe=recipe, ingredients=ingredients,
                           userid=userid, recreated_hashtag_input=recreated_hashtag_input)
Пример #6
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("/")
Пример #7
0
def edit_recipe(userid, recipeid):
    """Get a recipe from the db, and display it so the user can edit."""

    recipe = Recipe.get_recipe(recipeid)

    ingredients = Ingredient.get_recipe_ingredients(recipeid)

    recipe_hashtags = Recipe_Hashtag.get_recipe_hashtags(recipeid)

    hashtag_list = Recipe_Hashtag.get_hashtag_names_for_recipe(recipe_hashtags)

    readable_hashtags = Hashtag.get_readable_hashtags(hashtag_list)

    recreated_hashtag_input = Hashtag.recreate_hashtag_input(readable_hashtags)

    return render_template("edit_recipe.html",
                           recipe=recipe,
                           ingredients=ingredients,
                           userid=userid,
                           recreated_hashtag_input=recreated_hashtag_input)
Пример #8
0
def display_recipe(userid, recipeid):
    """Retrieves an individual recipe from db for display."""

    recipe = Recipe.get_recipe(recipeid)

    ingredients = Ingredient.get_recipe_ingredients(recipeid)

    recipe_hashtags = Recipe_Hashtag.get_recipe_hashtags(recipeid)

    return render_template("recipe_info.html", recipe=recipe,
                           ingredients=ingredients, recipe_hashtags=recipe_hashtags,
                           userid=userid)
Пример #9
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("/")
Пример #10
0
def display_recipe(userid, recipeid):
    """Retrieves an individual recipe from db for display."""

    recipe = Recipe.get_recipe(recipeid)

    ingredients = Ingredient.get_recipe_ingredients(recipeid)

    recipe_hashtags = Recipe_Hashtag.get_recipe_hashtags(recipeid)

    return render_template("recipe_info.html",
                           recipe=recipe,
                           ingredients=ingredients,
                           recipe_hashtags=recipe_hashtags,
                           userid=userid)