コード例 #1
0
def add_comment_like(comment_id, action):
    # getting story from db
    comment = Comment.query.get(comment_id)

    # checking if story exists
    if comment:
        if action == 'like':
            # adding like to db
            current_user.like_comment(comment)
            new_likes = comment.likes.count()
            db.session.commit()
            # adding new like end
            message = {"count": new_likes, "status": "success"}
            db.session.commit()
            return jsonify(message), 201

        if action == 'unlike':
            current_user.unlike_comment(comment)
            new_likes = comment.likes.count()
            message = {"count": new_likes, "status": "success"}
            db.session.commit()
            return jsonify(message), 201

    else:
        message = {"status": "failed"}
        return jsonify(message), 400
コード例 #2
0
def comment_action(comment_id, action):
    """ Comment actions.

    :param comment_id: ID of the comment to take action upon
    :param action: Action to take on comment
    """
    referrer = request.referrer
    comment = PostComment.query.filter_by(id=comment_id).first_or_404()
    # Delete comment.
    if action == 'delete-comment':
        if current_user == comment.author:
            referrer = url_for('users.post', post_id=comment.post.id)
            comment.delete()
            NotificationHelper(comment=comment).delete_comment()
            comment.commit()
            flash('Comment was deleted.')
    # Like comment.
    if action == 'like-comment':
        current_user.like_comment(comment)
        NotificationHelper(notified=comment.author,
                           notifier=current_user,
                           comment=comment,
                           post=comment.post).comment_like()
        current_user.commit()
    # Unlike comment.
    if action == 'unlike-comment':
        current_user.unlike_comment(comment)

        NotificationHelper(notifier=current_user,
                           comment=comment).delete_comment_like()

        current_user.commit()
    return redirect(referrer)
コード例 #3
0
def unlike_comment(id):
    comment = Comment.query.filter_by(id=id).first()
    if comment is None:
        flash('This comment is invalid or has been deleted by the user')
        return redirect(url_for('.home'))
    current_user.unlike_comment(comment)
    flash("You have unliked this comment")
    return redirect(url_for('.post', id=id))
コード例 #4
0
def like_action(comment_id, action):
    comment = Comment.query.filter_by(id=post_id).first_or_404()
    if action == 'vote':
        current_user.vote_comment(comment)
        db.session.commit()
    if action == 'downvote':
        current_user.unlike_comment(comment)
        db.session.commit()
    return redirect(request.referrer)
コード例 #5
0
def postcommentlike_action(comment_id, action):
    comment = Comment.query.filter_by(id=comment_id).first_or_404()
    if action == 'like':
        current_user.like_comment(comment)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_comment(comment)
        db.session.commit()
    return redirect(url_for('main.home'))
コード例 #6
0
ファイル: views.py プロジェクト: karthikeyansa/PyDev-Flask
def clike_action(comment_id, action):
    comment = Comments.query.filter_by(id=comment_id).first_or_404()
    if action == 'like':
        current_user.like_comment(comment)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_comment(comment)
        db.session.commit()
    return redirect(request.referrer)
コード例 #7
0
def like_comment():
    id = request.args.get('id')
    comment = Comment.query.filter_by(id=id).first()
    result = {'like': True}
    if current_user.has_liked_comment(comment):
        current_user.unlike_comment(comment)
        result = {'like': False}
        return jsonify(result)
    else:
        current_user.like_comment(comment)
        return jsonify(result)
コード例 #8
0
ファイル: posts.py プロジェクト: Frozander/Chirper
def like_comment(id, action):
    """
    Endpoint: comment/<b64:id>/like

    Handles : GET, POST

    API endpoint for liking comments.
    """

    comment = Comment.query.filter_by(id=id).first_or_404()

    if action == 'like':
        current_user.like_comment(comment)
    elif action == 'unlike':
        current_user.unlike_comment(comment)

    db.session.commit()
    return redirect(request.referrer)
コード例 #9
0
ファイル: routes.py プロジェクト: Jonathasgmc32/caravanitter
def like_comment(comment_id, action):
    comment = Comment.query.filter_by(id=comment_id).first_or_404()
    if action == 'like':
        current_user.like_comment(comment)
        db.session.commit()
        if current_user.id != comment.comment_author.id:
            notify = Notify(post_id=comment.post_id, causer_author=current_user, rec_id=comment.comment_author.id, action="curtiu seu comentário", content=comment.content)
            db.session.add(notify)
        db.session.commit()
    if action == 'unlike':
        current_user.unlike_comment(comment)
        notify = Notify.query.filter_by(post_id=comment.post_id, causer_author=current_user, rec_id=comment.comment_author.id).first()
        if notify != None:
            db.session.delete(notify)
        db.session.commit()
    if action == 'None':
        return render_template('error_500.html', title="Erro inesperado")
    return redirect(request.referrer)