Example #1
0
def social():
    user = Friend.objects(username=session["token"]).first()
    friends = user.friend
    friend_post = []
    posts = Post.objects()
    for post in posts:
        if post.user in friends:
            friend_post.append(post)
    return render_template("social.html", posts=friend_post)
Example #2
0
def unfollow():
    user = Friend.objects(username=session["token"]).first()
    friend_list = user.friend
    if request.method == "GET":
        return render_template("unfollow.html", friends=friend_list)
    else:
        form = request.form
        unf = form["unfollow"]
        friend_list.remove(unf)
        user.save()
        return redirect("/social/unfollow")
Example #3
0
def follow():
    error = None
    user = Friend.objects(username=session["token"]).first()
    friend_list = user.friend
    if request.method == "GET":
        return render_template("follow.html", friends=friend_list)
    else:
        form = request.form
        search_friend = form["add_friend"]
        exist_user = Friend.objects(username=search_friend).first()
        if exist_user == None:
            error = "user not found"
        elif exist_user.username == user.username:
            error = "cant follow yourself"
        elif exist_user.username in friend_list:
            error = "followed before"
        else:
            friend_list.append(search_friend)
            user.save()
            error = "done"
        return render_template("follow.html", error=error, friends=friend_list)
Example #4
0
def follow():
    error = None
    user = Friend.objects(username=session["token"]).first()
    friend_list = user.friend
    if request.method == "GET":
        return render_template("follow.html", friends=friend_list,name = session["token"],avt=user.avt)
    else:
        form = request.form
        search_friend = form["add_friend"]
        exist_user = Friend.objects(username=search_friend).first()
        if exist_user == None:
            error = "Không tìm thấy người dùng"
        elif exist_user.username == user.username:
            error = "Không thể tự theo dõi bản thân"
        elif exist_user.username in friend_list:
            error = "Đã theo dõi người dùng trước đó "
        else:
            friend_list.append(search_friend)
            user.save()
            error = "Thành công"
        return render_template("follow.html",error=error,friends = friend_list)
Example #5
0
def social():
    user = Friend.objects(username=session["token"]).first()
    us = User.objects(username=session["token"]).first()
    friends = user.friend
    friend_post = []
    posts = Post.objects()
    # commentss = []
    for post in posts:
        if post.user in friends or post.user == session["token"]:
            friend_post.append(post)
    print(friend_post)
    # for post in friend_post:
    #     commentss.append(post.comments)
    if request.method == "GET":
        return render_template("social.html",
                               posts=friend_post,
                               avt=us.avt,
                               name=session["token"])
    else:
        form = request.form
        for i in form:
            if "like" in i:
                like = form[i]
                if like != None:
                    for j in range(len(friend_post)):
                        if str(j + 1) in i:
                            p = friend_post[j]
                            print(p.like)
                            if session["token"] not in p.wholike:
                                p.like += 1
                                p.wholike.append(session["token"])
                            else:
                                p.like -= 1
                                p.wholike.remove(session["token"])

            else:
                comments = []
                comment = {}
                comment["contain"] = form[i]
                comment["owner"] = session["token"]
                if comment["contain"] != None:
                    for j in range(len(friend_post)):
                        if str(j + 1) in i:
                            p = friend_post[int(j)]
                            p.comments.append(comment)
            p.save()
    return redirect(url_for("social"))
def social():
    user = Friend.objects(username=session["token"]).first()
    friends = user.friend
    friend_post = []
    posts = Post.objects()
    who_like  = [] 
    for post in posts:
        if post.user in friends:
            friend_post.append(post)
    if request.method == "GET":
        return render_template("social.html",posts=friend_post) 
    else:
        form = request.form
        print(form) 
        for i in form: 
            if "like" in i:
                like = form[i]
                if like != None:
                    for j in range(len(friend_post)): 
                        if str(j+1) in i: 
                            p = friend_post[j] 
                            if session["token"] not in p.wholike:
                                p.like += 1 
                                p.wholike.append(session["token"])
                            else:
                                p.like -= 1 
                                p.wholike.remove(session["token"])
                                
            else:
                comment = form[i]
                if comment != None:
                    for j in range(len(friend_post)): 
                        if str(j+1) in i: 
                            p = friend_post[int(j)] 
                            p.comment.append(comment)
            p.save()
    return redirect(url_for("social"))