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
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)
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))
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)
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'))
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)
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)
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)
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)