Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
def remove_follower(followedid, followerid):


    db.engine.execute("DELETE FROM followers WHERE followedid = %s AND followerid = %s", followedid, followerid)

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

    return redirect(url_for('homepage'))
Esempio n. 5
0
def remove_like(postid):


    db.engine.execute("DELETE FROM likers WHERE liked_post = %s AND userid = %s", postid, current_user.id)
    db.engine.execute("UPDATE postss SET nlikes = nlikes - 1 where id = %s", postid)

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

    return redirect(url_for('homepage'))
Esempio n. 6
0
def showprofile(hisid):


    # users = db.engine.execute("SELECT * FROM users WHERE id = %s", hisid)
    userss = users.query.filter_by(id = hisid).first()

    # followers = db.engine.execute("SELECT * FROM followers where followerid = %s", current_user.id)



   

    image_file = url_for('static', filename='Images/' + userss.profilePic)

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

 
    recipes = rec.query.filter_by(user_id=hisid)
    favRecipes = favs.query.filter_by(user_id=hisid)
    followers = db.engine.execute("SELECT * FROM followers where followedid = %s", hisid)
    following = db.engine.execute("SELECT * FROM followers where followerid = %s", hisid)

    allposts = db.engine.execute("SELECT * from (select * from postss where user_id = %s) as a left join likers on a.id = likers.liked_post and likers.userid = %s ;",
        hisid, current_user.id )

    flag = "hello"

    for x in followers:
        if x.followedid == hisid: 
            flag = "hello2"

    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('ProfilePageOthers.html',flag = flag, title='Profile', form5=formsearch, followers = followers, following = following, users = userss, image_file=image_file, recipes=recipes, allPosts=allposts, form=form, form2=formNormalText, form3=formCurrent)
    elif count == 0 and count2 == 0:
        return render_template('ProfilePageOthers.html',flag = flag, title='Profile', form5=formsearch, followers = followers, following = following, users = userss, image_file=image_file, allPosts=allposts, form=form, form2=formNormalText, form3=formCurrent)
    elif count != 0 and count2 == 0:
        return render_template('ProfilePageOthers.html',flag = flag, title='Profile', form5=formsearch, followers = followers, following = following, users = userss, image_file=image_file, allPosts=allposts, form=form, form2=formNormalText, form3=formCurrent, favRecipes=favRecipes)
    else:
        return render_template('ProfilePageOthers.html',flag = flag, title='Profile', form5=formsearch, followers = followers, following = following, users = userss, image_file=image_file,recipes=recipes, allPosts=allposts, form=form, form2=formNormalText, form3=formCurrent, favRecipes=favRecipes)
Esempio n. 7
0
def add_follower(followedid, followedname):


    follower = followers(followerid = current_user.id, followedid = followedid, followername = current_user.username, followedname = followedname)
    db.session.add(follower)
    db.session.commit()

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

    return redirect(url_for('homepage'))
Esempio n. 8
0
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)
Esempio n. 9
0
def add_like(postid):

    print("Hello : ", postid)

    like = likers(liked_post = postid, userid = current_user.id)

    # luike = postss.query.filter_by(id=postid).first()
    db.engine.execute("UPDATE postss SET nlikes = nlikes + 1 where id = %s", postid)
    db.session.add(like)
    db.session.commit()

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

    return redirect(url_for('homepage'))
Esempio n. 10
0
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)
Esempio n. 11
0
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)