コード例 #1
0
ファイル: blog.py プロジェクト: Chennl/workblog
def likes(postid):
    if request.method == 'POST':
        like = Likes.query.filter(
            text("user_id=:uid and post_id=:pid")).params(uid=current_user.id,
                                                          pid=postid).first()
        if like:
            db.session.delete(like)
            db.session.commit()
            return jsonify({
                'message': '已取消点赞!',
                'user_id': current_user.id,
                'post_id': postid,
                'action': 'dislike'
            })
        likes = Likes(user_id=current_user.id, post_id=postid)
        db.session.add(likes)
        db.session.commit()
        data = request.get_json() or {}
        print(data)
        return jsonify({
            'message': '点赞成功!',
            'user_id': current_user.id,
            'post_id': postid,
            'action': 'like'
        })
    else:
        return jsonify({'message': '~~'})
コード例 #2
0
def likes(post_id):
    
    like = Likes(user_id=g.current_user['user_id'],post_id=post_id)
    db.session.add(like)
    db.session.commit()
        
    return jsonify({'message':'sucess'})
コード例 #3
0
ファイル: routes.py プロジェクト: eshwarhs/CMovies
def like(movie_id):
    like = Likes(userid=current_user.userid,
                 movieid=movie_id,
                 timestamp=datetime.now())
    x = Likes.query.filter_by(movieid=movie_id,
                              userid=current_user.userid).first()
    if not x:
        db.session.add(like)
        db.session.commit()
    else:
        db.session.delete(x)
        db.session.commit()
    url = str(request.referrer)
    if ('search' in url):
        x = url.split("/")
        #print(x)
        return redirect(url_for('search', search_text=str(x[-1])))
    elif ('info' in url):
        x = url.split("/")
        #print(x)
        return redirect(url_for('info', video_id=str(x[-1])))
    elif ('watch' in url):
        x = url.split("/")
        return redirect(url_for('watch', youtube_id=str(x[-1])))
    else:
        url = url.split("/")[-1]
    return redirect(url_for(url))
コード例 #4
0
ファイル: views.py プロジェクト: damainross/info3180-project2
def like(post_id):

    request_payload = request.get_json()
    user_id = request_payload['user_id']
    post_id = request_payload['post_id']

    post = Posts.query.filter_by(id=post_id)

    if post is None:
        return jsonify(message="This post does not exist.")

    postLikes = Likes.query.filter_by(post_id=post_id).all()

    if postLikes is not None:
        for like in postLikes:
            if like.user_id == user_id:
                return jsonify(message="This post is liked already.")

    newLike = Likes(post_id, user_id)
    db.session.add(newLike)
    db.session.commit()

    totalLikes = len(Likes.query.filter_by(post_id=post_id)).all()
    info = [{'message': "Post liked!", 'likes': totalLikes}]
    return jsonify(info=info)
コード例 #5
0
ファイル: routes.py プロジェクト: Abalmaz/Board_flask
def likes_board(board_id):
    like = Likes(user_id=session["user_id"], board_id=board_id)
    if can_likes():
        db.session.add(like)
        db.session.commit()
        session["count_likes"] -= 1
        return redirect('/%s' % board_id)
    else:
        return jsonify({'error': 'You have reached your likes limit in hour'})
コード例 #6
0
ファイル: views.py プロジェクト: Ta-von/info3180-project2
def Like(post_id):
    LikerID = current_user.id
    LikeCheck=Likes.query.filter_by(user_id=LikerID,post_id=post_id).first()
    if LikeCheck is None:
        LikedPost = Likes(LikerID,post_id)
        db.session.add(LikedPost)
        db.session.commit()
        return jsonify(Like = "New Like!",likestatus = "free")
    else:
        return jsonify(greedy = "You have already liked this post!",likestatus = "done")
コード例 #7
0
def addlikes(post_id):
    token = request.headers['Authorization'].split()[1]
    current_id = jwt.decode(token,
                            app.config['SECRET_KEY'],
                            algorithms=['HS256'])['id']
    like = Likes(current_id, post_id)
    db.session.add(like)
    db.session.commit()

    return jsonify({"message": "liked"}), 201
コード例 #8
0
def like(post_id):
    """Set a like on the current Post by the logged in User"""
    check_likes = Likes.query.filter_by(user_id=session['userid'],
                                        post_id=postid).first()
    if (check_likes is None):
        like = Likes(user_id=session['userid'], post_id=post_id)
        db.session.add(like)
        db.session.commit()
        return jsonify(message='You have liked a post')
    return jsonify(DB='You already liked the post')
コード例 #9
0
def like(post_id):
    if request.method("POST"):
        likes = Likes(current_user.id, post_id)
        db.session.add(likes)
        db.session.commit()
        currentlikes = (Likes.query.filter_by(post_id=post_id).first()).user_id.count()
        likesmessage = {
            "message": "Post liked!",
            "likes": currentlikes
        }
        return jsonify(likesmessage=likesmessage)
コード例 #10
0
def likePost(post_id):
    post = db.session.query(Posts).filter_by(id=post_id).first()
    if current_user.is_authenticated():
        id = current_user.id
        like = Likes(id, post_id)
        db.session.add(like)
        db.session.commit()
        return jsonify(message="Post Liked!", likes=len(post.likes)), 201

    #Flash message to indicate that an error occurred
    failure = "Failed to like post"
    return jsonify(error=failure)
コード例 #11
0
def like(postid):
    like = LikeForm()
    if request.method == "POST":
        like.userid.data = request.form['userid']
        if like.validate_on_submit():
            userid = like.userid.data

            likeDB = Likes(userid, postid)
            db.session.add(likeDB)
            db.session.commit()
            return jsonify(message="successful")

    return jsonify(message="failed")
コード例 #12
0
def like_add():
    uid = request.args.get("uid", "")
    mid = request.args.get("mid", "")
    like = Likes.query.filter_by(user_id=int(uid), movie_id=int(mid)).count()
    if like == 1:
        data = dict(ok=0)
    else:
        like = Likes(user_id=int(uid), movie_id=int(mid))
        data = dict(ok=1)
        db.session.add(like)
        db.session.commit()
    import json
    return json.dumps(data)
コード例 #13
0
ファイル: views.py プロジェクト: Don-Droid/INFO3180-project2
def like(post_id):
    if request.method == "POST":
        auth = request.headers.get('Authorization', None)
        parts = auth.split()
        if parts[0].lower() == 'bearer':
            token = parts[1]
            liker = jwt.decode(token, 'app.config[SECRET_KEY]')

            like = Likes(user_id=int(liker['user_Id']), post_id=int(post_id))
            db.session.add(like)
            db.session.commit()
            return all_post()
    return jsonify({"Follow": "failed"})
コード例 #14
0
def like(post_id):
    """ Like a post """

    post = PostModel.query.filter_by(post_id).first()

    if request.method == 'POST':

        like = Likes(session['current_user'], post_id)

        db.session.add(like)
        db.session.commit
        likes = len(Likes.query.filter_by(post_id=post_id).all())
        msg = {"message": "Post Liked!", "likes": likes}
        return jsonify(msg)
    return jsonify(["Bad Request"])
コード例 #15
0
ファイル: routes.py プロジェクト: Rajeshsingh127/petbook
def likes(postid):
    post_id = int(postid)
    add = Upload.query.filter_by(id=post_id).first()
    check = Likes.query.filter_by(userid=current_user.id,post_id=post_id).first()
    if check is not None:
        db.session.delete(check)
        add.likes -= 1
        db.session.commit()
        return redirect(request.referrer)
    else:
        poop = Likes(userid=current_user.id, post_id=int(post_id))
        db.session.add(poop)
        add.likes += 1
        db.session.commit()
        return redirect(request.referrer)
コード例 #16
0
def like(post_id):
    requests= request.get_json()
    post_id = requests["post_id"]
    user_id = requests["user_id"]
    postx = Post.query.filter_by(post_id=post_id).first()
    likesx = Likes.query.filter_by(post_id=post_id).all()
    if likesx is not None:
        for like in likesx:
            if like.id == user_id:
                return jsonify(message="Post has been liked already.")
    added = Likes(id = user_id,post_id = post_id)
    db.session.add(added)
    db.session.commit()
    tlikes = len(Likes.query.filter_by(post_id=post_id).all())
    return jsonify({"message": 'Post liked', "likes":tlikes })
コード例 #17
0
ファイル: main.py プロジェクト: fredcodee/Blog
def likes(idd):
    #check if user has like before and unlike
    check_user = Likes.query.filter(Likes.blogpost_likes.has(id=int(idd)))
    for user in check_user:
        if user.user_likes.name == current_user.name:
            db.session.delete(user)
            db.session.commit()
            return redirect(url_for("main.blog", idd=idd))

    get_blog = Blogpost.query.get(int(idd))
    new_like = Likes(user_likes=current_user, blogpost_likes=get_blog)

    db.session.add(new_like)
    db.session.commit()
    flash("post liked!")
    return redirect(url_for("main.blog", idd=idd))
コード例 #18
0
def like(post_id):
    findLike = Likes.query.filter_by(user_id=current_user.id,
                                     post_id=post_id).first()
    if findLike is None:
        like = Likes(user_id=current_user.id, post_id=post_id)
        db.session.add(like)
        db.session.commit()
        numberOfLikes = Likes.query.filter_by(post_id=post_id).count()
        succesMessage = {"message": "Post liked!", "likes": numberOfLikes}
        return jsonify(succesMessage=succesMessage)
    else:
        Likes.query.filter_by(user_id=current_user.id,
                              post_id=post_id).delete()
        db.session.commit()
        numberOfLikes = Likes.query.filter_by(post_id=post_id).count()
        succesMessage = {"message": "Post unliked!", "likes": numberOfLikes}
        return jsonify(succesMessage=succesMessage)
コード例 #19
0
def like(post_id):
    form = LikesForm()

    if form.validate_on_submit():

        user_id = form.user_id.data
        like = Likes(user_id, post_id)
        try:
            post = db.session.query(Posts).filter_by(id=post_id).first()
            db.session.add(like)
            db.session.commit()
            response = "Post Liked!"
            return jsonify(message=response, likes=len(post.likes)), 200
        except:
            response = "could not like post"
            return jsonify(error=response), 400

    response = "Failed to like the post, Something went wrong with the form"
    return jsonify(error=response), 400
コード例 #20
0
def like_actors():
    if request.method == "GET":
        actor_id = request.args.get('actor_id').replace('likeButton', '')
        user_id = session['userid']
        result = Likes.query.filter(
            and_(actor_id == Likes.actor_id, user_id == Likes.user_id)).all()
        db.session.close()
        response = {}
        if len(result) > 0:
            # 该演员目前为喜欢状态,再次点击即代表取消操作,执行delete
            db.session.query(Likes).filter(
                and_(actor_id == Likes.actor_id,
                     user_id == Likes.user_id)).delete()
            db.session.commit()
            response['type'] = 'unlike'
        elif len(result) == 0:
            # 该演员目前为不喜欢状态,再次点击即代表新增操作,执行add
            like = Likes(user_id, actor_id)
            db.session.add(like)
            db.session.commit()
            response['type'] = 'like'
        return response