コード例 #1
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def update_post(post_id):
    post = postss.query.get(post_id)


    formsearch = RecipeSearchForm()

    form = PostFormHungryFor()
    if form.validate_on_submit():
        hungryFood = "I am hungry for " + form.content.data
        db.engine.execute("UPDATE postss SET content = %s WHERE ID = %s", (hungryFood, post_id))
        db.session.commit()
        return redirect(url_for('profile'))

    form3 = PostForm()
    if form3.validate_on_submit():
        db.engine.execute("UPDATE postss SET content = %s WHERE ID = %s", form3.contentNormal.data, post_id)
        db.session.commit()
        return redirect(url_for('profile'))
        
    form2 = PostFormCurrentlyEating()
    if form2.validate_on_submit():
        db.engine.execute("UPDATE postss SET content_current = %s, link_current = %s WHERE ID = %s", form2.contentCurrent.data, form2.linkCurrent.data, post_id)
        db.session.commit()
        return redirect(url_for('profile'))



    if post.post_type == "hungryFor":
        return render_template('editPost.html', form=form, form5=formsearch, post=post)
    elif post.post_type == "currentlyEating":
        return render_template('editPost2.html', form=form2, form5=formsearch, post=post)
    else:
        return render_template('editPost3.html', form=form3, form5=formsearch, post=post)
コード例 #2
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def settings():
    formsearch = RecipeSearchForm()

    form = UpdateProfileForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            print(picture_file)
            db.engine.execute("UPDATE users SET profilePic = %s WHERE id = %s", (picture_file, current_user.id))
        if(is_filled(form.username.data)):
            db.engine.execute("UPDATE users SET username = %s WHERE id = %s", (form.username.data, current_user.id))
        if(is_filled(form.firstname.data)):
            db.engine.execute("UPDATE users SET firstname = %s WHERE id = %s", (form.firstname.data, current_user.id))
        if(is_filled(form.lastname.data)):
            db.engine.execute("UPDATE users SET lastname = %s WHERE id = %s", (form.lastname.data, current_user.id))
        if(is_filled(form.email.data)):
            db.engine.execute("UPDATE users SET firstname = %s WHERE id = %s", (form.firstname.data, current_user.id))
        if(is_filled(form.cooking_exp.data)):
            db.engine.execute("UPDATE users SET cookingExperience = %s WHERE id = %s", (form.cooking_exp.data, current_user.id))
        return redirect(url_for('profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.firstname.data = current_user.firstName
        form.lastname.data = current_user.lastName
        form.email.data = current_user.email
        form.cooking_exp.data = current_user.cookingExperience
    return render_template('usersettings.html', form=form, form5=formsearch)

    return render_template('usersettings.html', form5=formsearch)
コード例 #3
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def profile():

    followers = db.engine.execute("SELECT * FROM followers where followedid = %s", current_user.id)
    following = db.engine.execute("SELECT * FROM followers where followerid = %s", current_user.id)
    formsearch = RecipeSearchForm()

    form = PostFormHungryFor()

    if form.validate_on_submit():
        toSend = "I am hungry for " + form.content.data
        post = postss(content=toSend, user_id=current_user.id, post_type="hungryFor")
        db.session.add(post)
        db.session.commit()
        flash('Your post has created', 'success')
        return redirect(url_for('profile'))

    formNormalText = PostForm()

    if formNormalText.validate_on_submit():
        post2 = postss(content=formNormalText.contentNormal.data, user_id=current_user.id, post_type="boringPost")
        db.session.add(post2)
        db.session.commit()
        flash('Your post has created', 'success')
        return redirect(url_for('profile'))

    formCurrent = PostFormCurrentlyEating()

    if formCurrent.validate_on_submit():
        post3 = postss(content_current=formCurrent.contentCurrent.data, link_current=formCurrent.linkCurrent.data, user_id=current_user.id, post_type="currentlyEating")
        db.session.add(post3)
        db.session.commit()
        flash('Your post has created', 'success')
        return redirect(url_for('profile'))

    allposts = postss.query.filter_by(user_id=current_user.id)

    recipes = rec.query.filter_by(user_id=current_user.id)
    favRecipes = favs.query.filter_by(user_id=current_user.id)

    image_file = url_for('static', filename='Images/' + current_user.profilePic)
    count2 = 0

    for x in recipes:
        count2 = count2 + 1

    count = 0

    for x in favRecipes:
        count = count + 1

    if count == 0 and count2 != 0:
        return render_template('ProfilePage.html', title='Profile', form5=formsearch, followers = followers, following = following, recipes=recipes, image_file=image_file, allPosts=allposts, form=form, form2=formNormalText, form3=formCurrent)
    elif count == 0 and count2 == 0:
        return render_template('ProfilePage.html', title='Profile', form5=formsearch, followers = followers, following = following, image_file=image_file, allPosts=allposts, form=form, form2=formNormalText, form3=formCurrent)
    elif count != 0 and count2 == 0:
        return render_template('ProfilePage.html', title='Profile', form5=formsearch, followers = followers, following = following, image_file=image_file, allPosts=allposts, form=form, form2=formNormalText, form3=formCurrent, favRecipes=favRecipes)
    else:
        return render_template('ProfilePage.html', title='Profile', form5=formsearch, followers = followers, following = following, recipes=recipes, image_file=image_file, allPosts=allposts, form=form, form2=formNormalText, form3=formCurrent, favRecipes=favRecipes)
コード例 #4
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def search():

    formsearch = RecipeSearchForm()
    form = PostFormHungryFor()
    formNormalText = PostForm()
    formCurrent = PostFormCurrentlyEating()

    if request.method == 'POST':

        minmax = request.form['minmax']
        minmax = minmax.replace('-', '')
        minmax = minmax.replace('$', '').split()

        calories = request.form['calories']
        calories = calories.replace('-', '')
        calories = calories.replace('$', '').split()

    if formsearch.validate_on_submit():
        if is_filled(formsearch.keyWord.data):
            keywords = parser_first_round(formsearch.keyWord.data)
            keywords_sufix = parser_search_sufix(formsearch.keyWord.data)
            print(keywords_sufix)

            print(keywords)

            recipes = db.engine.execute("SELECT * FROM (SELECT * FROM rec WHERE (minPrice <= %s AND maxprice >= %s) AND ( calories >= %s AND calories <= %s ) AND \
                ((MATCH (rec_name, rec_description, rec_instruction, ings, tags) \
                    AGAINST (%s IN BOOLEAN MODE)))) as b left join (select id as useridd, username from users) as a on b.user_id = a.useridd \
                    UNION \
                    SELECT * FROM (SELECT * FROM rec where rec_name LIKE %s)  as b left join (select id as useridd, username from users) as a on b.user_id = a.useridd  \
                    ", minmax[1], minmax[0], calories[0], calories[1], keywords, keywords_sufix )


            return render_template('homepage.html', form5=formsearch, form=form, form2=formNormalText, form3=formCurrent, recipes=recipes)



        else:

            recipes = db.engine.execute("SELECT * FROM rec WHERE (minPrice <= %s AND maxprice >= %s) AND ( calories >= %s AND calories <= %s )", minmax[1], minmax[0], calories[0], calories[1])
            return render_template('homepage.html', form5=formsearch, form=form, form2=formNormalText, form3=formCurrent, recipes=recipes)

    return render_template('homepage.html', form5=formsearch, form=form, form2=formNormalText, form3=formCurrent)
コード例 #5
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def homepage():

    formsearch = RecipeSearchForm()

    # favRecipes = favs.query.filter_by(user_id=current_user.id)
    form = PostFormHungryFor()
    if current_user.is_authenticated:
        # allrecipes = db.engine.execute("SELECT rec_name, rec_description, user_id, recipePic, dateposted, username, followername, rating from  (rec  left join (select id, username from users) as a on rec.user_id = a.id) left join followers on (followers.followedid = rec.user_id and followerid = %s)", current_user.id)
        # allposts = db.engine.execute("SELECT content_current, content, user_id, link_current, post_date, username, followername, followerid from \
        #                                 postss left join (select id, username from users) as a on postss.user_id = a.id \
        #                                     left join followers on (followers.followedid = postss.user_id and followerid = %s)", current_user.id )
        allrecipes = db.engine.execute("SELECT rec.id as id, rec_name, rec_description, user_id, recipePic, dateposted, username, followername, rating, number_of_ratings  from  (rec  left join (select id, username from users) as a on rec.user_id = a.id) \
                                            left join followers on (followers.followedid = rec.user_id and followerid = %s) \
                                        UNION \
                                        select b.id, content_current, content, user_id, link_current, post_date, username, followername, userid, nlikes from \
                                        (select * from postss left join likers on postss.id = likers.liked_post and likers.userid = %s) as b left join (select id, username from users) as a on b.user_id = a.id \
                                            left join followers on (followers.followedid = b.user_id and followerid = %s) \
                                        ORDER BY dateposted desc;", current_user.id, current_user.id, current_user.id)

    else:
        allrecipes = db.engine.execute("SELECT rec.id as id, rec_name, rec_description, user_id, recipePic, dateposted, username, rating, number_of_ratings  from  (rec  left join (select id, username from users) as a on rec.user_id = a.id) \
                                        UNION \
                                        select postss.id, content_current, content, user_id, link_current, post_date, username, a.id, nlikes from  (postss  left join (select id , username from users) as a on postss.user_id = a.id) \
                                        ORDER BY dateposted desc;")

    if form.validate_on_submit():
        toSend = "I am hungry for " + form.content.data
        post = postss(content=toSend, user_id=current_user.id, post_type="hungryFor")
        db.session.add(post)
        db.session.commit()
        flash('Your post has created', 'success')
        return redirect(url_for('homepage'))

    formNormalText = PostForm()

    if formNormalText.validate_on_submit():
        post2 = postss(content=formNormalText.contentNormal.data, user_id=current_user.id, post_type="boringPost")
        db.session.add(post2)
        db.session.commit()
        flash('Your post has created', 'success')
        return redirect(url_for('homepage'))

    formCurrent = PostFormCurrentlyEating()

    if formCurrent.validate_on_submit():
        post3 = postss(content_current=formCurrent.contentCurrent.data, link_current=formCurrent.linkCurrent.data, user_id=current_user.id, post_type="currentlyEating")
        db.session.add(post3)
        db.session.commit()
        flash('Your post has created', 'success')
        return redirect(url_for('homepage'))

    return render_template('homepage.html', title='Home', form5=formsearch, form=form, form2=formNormalText, form3=formCurrent, allrecipes=allrecipes)
コード例 #6
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def searchthings(thing):

    formsearch = RecipeSearchForm()
    form = PostFormHungryFor()
    formNormalText = PostForm()
    formCurrent = PostFormCurrentlyEating()

    if thing is "":
        return render_template('homepage.html', form5=formsearch, form=form, form2=formNormalText, form3=formCurrent)

    else:

        recipes = db.engine.execute("SELECT * FROM (SELECT * FROM rec WHERE ((MATCH (rec_name, ings, tags) \
                AGAINST (%s IN BOOLEAN MODE)))) as b left join (select id as useridd, username from users) as a on b.user_id = a.useridd;", thing)
        return render_template('homepage.html', form5=formsearch, form=form, form2=formNormalText, form3=formCurrent, recipes=recipes)
コード例 #7
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def showrecipe(recipe_id):

    formsearch = RecipeSearchForm()
    recc = db.engine.execute("SELECT * from (select * from rec where id = %s) as a left join raters on raters.userid = %s and raters.rated_recipe = %s LIMIT 1", recipe_id, current_user.id, recipe_id).first()

    


    if recc.number_of_ratings is 0: 
        totalRating = 0
    else:
        totalRating = float(recc.rating)/float(recc.number_of_ratings)

    # checkRating = raters.query.filter_by(rated_recipe = recipe_id, userid = current_user.id)
    
    return render_template('recipespage.html', title=recc.rec_name, rec=recc, form5=formsearch,totalRating=round(totalRating, 1))
コード例 #8
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def update_recipe(recipe_id):
    recipee = rec.query.get(recipe_id)
    formsearch = RecipeSearchForm()

    form = RecipeForm()

    if form.validate_on_submit():
        if form.recipePic.data:
            recipe_file = save_picture(form.recipePic.data)
            print(recipe_file)
            db.engine.execute("UPDATE rec SET recipePic = %s WHERE id = %s", (recipe_file, recipe_id))
        reRec_name = form.rec_name.data
        rePrep_time = form.prep_time.data
        reCook_time = form.cook_time.data
        if len(form.rec_description.data)==0:
                reRec_description= recipee.rec_description
        else:
            reRec_description = form.rec_description.data
        if len(form.rec_instruction.data)==0:
            reRec_instruction= recipee.rec_instruction
        else:
            reRec_instruction = form.rec_instruction.data
        ings = form.ings.data

        tags = form.tags.data

        reCalories = form.calories.data
        reFat = form.fat.data
        reCholesterol = form.cholesterol.data
        reSodium = form.sodium.data
        reMinPrice = form.minPrice.data
        reMaxPrice = form.maxPrice.data
        print("add recipe")
        db.engine.execute("UPDATE rec SET rec_name = %s, prep_time = %s, cook_time = %s, rec_description = %s, rec_instruction = %s, ings = %s, tags = %s, minPrice = %s, maxPrice = %s,calories = %s,fat = %s, cholesterol = %s, sodium = %s WHERE ID = %s",
            (reRec_name, rePrep_time, reCook_time, reRec_description,reRec_instruction, ings, tags,reMinPrice,reMaxPrice, reCalories, reFat, reCholesterol, reSodium, recipe_id))
        db.session.commit()
        return redirect(url_for('profile'))

    return render_template('editRecipe.html',form = form, form5 = formsearch, rec=recipee)
コード例 #9
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def create_recipe():
    formsearch = RecipeSearchForm()

    form = RecipeForm()

    if form.validate_on_submit():


        if form.recipePic.data:
            recipe_file = save_picture(form.recipePic.data)
            recipe = rec(rec_name=form.rec_name.data, prep_time=form.prep_time.data, cook_time=form.cook_time.data, rec_description=form.rec_description.data, rec_instruction=form.rec_instruction.data, ings=form.ings.data, tags=form.tags.data, calories=form.calories.data, fat=form.fat.data, cholesterol=form.cholesterol.data, sodium=form.sodium.data, user_id=current_user.id, minPrice=form.minPrice.data, maxPrice=form.maxPrice.data, recipePic=recipe_file, rating = 0, number_of_ratings = 0)
        else:
            print("RECIPE NAME: " + form.rec_name.data)
            recipe = rec(rec_name=form.rec_name.data, prep_time=form.prep_time.data, cook_time=form.cook_time.data, rec_description=form.rec_description.data, rec_instruction=form.rec_instruction.data, ings=form.ings.data, tags=form.tags.data, calories=form.calories.data, fat=form.fat.data, cholesterol=form.cholesterol.data, sodium=form.sodium.data, user_id=current_user.id, minPrice=form.minPrice.data, maxPrice=form.maxPrice.data, rating = 0, number_of_ratings = 0)

        print("add")
        db.session.add(recipe)
        db.session.commit()
        flash('Your post has been created!', 'success')
        return redirect(url_for('profile'))

    return render_template('createrecipe.html', title='New Recipe', form=form, form5=formsearch)
コード例 #10
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def searchadvanced(things):
    print("things")
    print(things)

    formsearch = RecipeSearchForm()
    form = PostFormHungryFor()
    formNormalText = PostForm()
    formCurrent = PostFormCurrentlyEating()

    if things is "":

        return render_template('homepage.html', form5=formsearch, form=form, form2=formNormalText, form3=formCurrent)

    else:
        words = things.split(';')
        words = list(filter(None, words))
        print(words)
        words = " ".join(words)
        recipes = db.engine.execute("SELECT * FROM (SELECT * FROM rec WHERE ((MATCH (rec_name, ings, tags) \
                AGAINST (%s IN BOOLEAN MODE)))) as b left join (select id as useridd, username from users) as a on b.user_id = a.useridd;", words)

        return render_template('homepage.html', form5=formsearch, form=form, form2=formNormalText, form3=formCurrent, recipes=recipes)

    return render_template('homepage.html', form5=formsearch,  form=form, form2=formNormalText, form3=formCurrent)
コード例 #11
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def favorites():
    formsearch = RecipeSearchForm()
    favsss = favs.query.filter_by(user_id=current_user.id)
 
    return render_template('favoritesPage.html',title='Favorites Page', favorites=favsss, form5=formsearch)
コード例 #12
0
ファイル: routes.py プロジェクト: abigehl/Cs307GroupProject
def advancedsearch():
    formsearch = RecipeSearchForm()
    print(formsearch.keyWord.data)
    if formsearch.validate_on_submit():
        print(formsearch.keyWord.data)
    return render_template("advancedsearchpage.html", form5=formsearch)