Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def get(self, userid):
        """Get a list of all of a user's hashtags."""

        user_tags = Hashtag.get_hashtags_by_user(userid)

        tags_list = [t[0] for t in user_tags]

        return {'hashtags': tags_list}
Ejemplo n.º 3
0
    def get(self, userid):
        """Get a list of all of a user's hashtags."""

        user_tags = Hashtag.get_hashtags_by_user(userid)

        tags_list = [t[0] for t in user_tags]

        return {'hashtags': tags_list}
Ejemplo n.º 4
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)
Ejemplo n.º 5
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))
Ejemplo n.º 6
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))
Ejemplo n.º 7
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("/")
Ejemplo n.º 8
0
def upload_file():
    """Allow user to upload photos"""

    file = request.files['file']
    caption = request.form['caption']
    hashtag = request.form['hashtag']

    user_id = session['user_id']

    if file.name == '':
        flash('No selected photos')
        return redirect(request.url)

    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        file_path = os.path.join(UPLOAD_FOLDER, filename)
        file.save(file_path)
        flash('Photo successfully uploaded')

        photo_user_id = session.get('user_id')

        new_photo = Photo(photo_user_id=photo_user_id,
                          photo_url=('/' + file_path),
                          caption=caption)

        db_hashtag = Hashtag.query.filter_by(hashtag=hashtag).first()

        if not db_hashtag:
            db_hashtag = Hashtag(hashtag=hashtag)

        new_photo.hashtags.append(db_hashtag)

        db.session.add(new_photo)
        db.session.commit()

        return redirect(f'/users/{user_id}')

    else:
        flash('Only png, jpg, jpeg, gif file types are allowed!')
        return redirect(request.url)
Ejemplo n.º 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("/")
Ejemplo n.º 10
0
def get_suggestions():
    """Get user data for typeahead suggestions."""

    userid = session['User']

    #### Hashtag Data ####
    hashtag_data = Hashtag.get_hashtags_by_user(userid)
    hashtag_list = [h[0] for h in hashtag_data]

    #### Recipe Data ####
    recipe_data = Recipe.get_user_recipe_list(userid)
    recipe_list = [r[1] for r in recipe_data]

    #### Ingredient Data ####
    ingredient_data = Ingredient.get_ingredients_by_user(userid)
    # convert to set then back to list to remove duplicates
    ingredient_list = list(set([i[0] for i in ingredient_data]))

    #### Combined Data ####
    data_list = hashtag_list + recipe_list + ingredient_list

    return jsonify({"userdata": data_list})
Ejemplo n.º 11
0
def get_suggestions():
    """Get user data for typeahead suggestions."""

    userid = session['User']

    #### Hashtag Data ####
    hashtag_data = Hashtag.get_hashtags_by_user(userid)
    hashtag_list = [h[0] for h in hashtag_data]

    #### Recipe Data ####
    recipe_data = Recipe.get_user_recipe_list(userid)
    recipe_list = [r[1] for r in recipe_data]

    #### Ingredient Data ####
    ingredient_data = Ingredient.get_ingredients_by_user(userid)
    # convert to set then back to list to remove duplicates
    ingredient_list = list(set([i[0] for i in ingredient_data]))

    #### Combined Data ####
    data_list = hashtag_list + recipe_list + ingredient_list

    return jsonify({"userdata": data_list})
Ejemplo n.º 12
0
def load_user_moods(): 

    User_Moods.query.delete()
    
    user_mood_1= User_Moods(user_id=0, 
        mood_id=5, 
        datetime='2018-01-01 12:00:00',
        comments= "Feeling average...",
        hours_slept=8,
        exercise_mins=60)

    db.session.add(user_mood_1)
    db.session.commit()
    
    mood_pots = [1,2,3,4,5, 5,5, 5, 5, 6,6,6, 6,7,8,9,9,10,10,10,10,10]
    comments_pots = ["Feeling Average", "Positive Vibes", "Need Caffeine", "Sunny Day!", "Went for a walk", "Good times with friends", "Travel Fun", "Gloomy", "Too much caffeine", "Great Day", "Worked Overtime", "Cooked Dinner", "Beach Day", "PTO, Woo!", "Cranky today", ]
    hashtag_pots = [ "#Blessed", "#StillBlessed", "#RainyDay", "#BailedOnPlans", "#LegDay", "#WhenisFriYAY", "#Hungry" ,"#Bored", "#ItsHandled", "#TheStruggleIsReal", "#GoodTimes", "#WFH", "#Motivated", "#MoreSleepPlz", "#CoffeeBreaks", "#Glad2BeHere"]
    exercise_pots = [0,30,60,60,90,180,0,30]
    
    i = 1
    while i < 50:
        #never sad 
        #mood_id = random.randint(5,10)
        #high variation 
        #mood_pots = [1,1,1,2,2,2,3,4,6,7,8,9,9,10,10,10,10,10]
        #mood_id = random.choice(mood_pots)
        #mostly happy
        comments = random.choice(comments_pots)
        mood_id = random.choice(mood_pots)
        hours_slept = random.randint(0,2)+mood_id
        exercise_mins = random.choice(exercise_pots)
        month = 1+ int(i/27)
        day = i % 27 + 1
        
        # query for hashtag by text field
        # if it's NOT in the hashtag table, add it
        
       
        hashtag_text = random.choice(hashtag_pots)

        hashtag = Hashtag.query.filter(Hashtag.text == hashtag_text).first()
        if hashtag is None:
            hashtag = Hashtag(text=hashtag_text)
            db.session.add(hashtag)
            db.session.commit()

        user_mood_rnd = User_Moods(user_id=0, 
        mood_id=mood_id, 
        datetime='2018-' + str(month) +'-'+str(day) + ' 12:00:00',
        comments=comments,
        #comments= "Feeling average...",
        hours_slept= hours_slept,
        exercise_mins=exercise_mins)

        db.session.add(user_mood_rnd)
        db.session.commit()

        userdatahashtag = UserDataHashtags(hashtag_id=hashtag.hashtag_id, record_id=user_mood_rnd.record_id)
        
        db.session.add(userdatahashtag)
        db.session.commit()

        i+=1


# def load_user_hashtags():
#     Hashtag.query.delete()

#     i = 1 
#     while i < 50:
#         hashtag_pots = [ "#Blessed", "#StillBlessed", "#LegDay" "#WhenisFriYAY", "#Hungry" "#Bored", "#ItsHandled", "#TheStruggleIsReal", "#GoodTimes", "#WFH", "#Motivated", "#MoreSleepPlz" "#CoffeeBreaks", "#Glad2BeHere"]
#         hashtag_rnd = Hashtag(text=random.choice(hashtatg_pots))
#         db.session.add(hashtag_rnd)

#         db.session(commit)

#class Hashtag(db.Model):
    """ Table of all hashtags with an id, for searching later"""