def like_action_comment(post_id, comment_id, action): ''' Adds or removes a like/dislike to or from a comment ''' post = Posts.query.get_or_404(post_id) comment = Comment.query.get_or_404(comment_id) if action == 'like': if current_user.has_disliked_comment: current_user.undislike_post(post=None, comment=comment) current_user.like_post(post=None, comment=comment) db.session.commit() if action == 'unlike': current_user.unlike_post(post=None, comment=comment) db.session.commit() if action == 'dislike': if current_user.has_liked_comment: current_user.unlike_post(post=None, comment=comment) current_user.dislike_post(post=None, comment=comment) db.session.commit() if action == 'undislike': current_user.undislike_post(post=None, comment=comment) db.session.commit() return redirect( url_for('boards.selected_comment', topic_address=post.topic, post_id=post_id, comment_id=comment_id))
def like_action(post_id, action): post = Post.query.filter_by(id=post_id).first_or_404() if request.method == 'POST': if action == 'like': if current_user.has_disliked_post(post): current_user.undislike_post(post) db.session.commit() if current_user.has_liked_post(post): current_user.unlike_post(post) db.session.commit() else: print('like') current_user.like_post(post) db.session.commit() return succesful_response({'message': 'Great Success!'}) if action == 'dislike': if current_user.has_liked_post(post): current_user.unlike_post(post) db.session.commit() if current_user.has_disliked_post(post): current_user.undislike_post(post) db.session.commit() else: current_user.dislike_post(post) db.session.commit() return succesful_response({'message': 'Great Success!'}) if request.method == 'GET': if current_user.has_liked_post(post): liked = True disliked = False elif current_user.has_disliked_post(post): liked = False disliked = True else: liked = False disliked = False data = { 'likes': post.likes.count(), 'dislikes': post.dislikes.count(), 'liked': liked, 'disliked': disliked } return data # @app.route('/profile/<', methods=['GET', 'POST']) # @login_required # def like_action(post_id, action):
def dislike_action(post_id, action): post = Post.query.filter_by(id=post_id).first_or_404() if action == 'dislike': current_user.dislike_post(post) db.session.commit() if action == 'undislike': current_user.undislike_post(post) db.session.commit() return redirect(request.referrer)
def like_action(post_id, action): post = Post.query.get_or_404(post_id) if action == 'like': current_user.like_post(post) current_user.undislike_post(post) db.session.commit() if action == 'unlike': current_user.unlike_post(post) db.session.commit() return redirect(request.referrer)
def dislike_action(post_id, action): post = Post.query.filter_by(id=post_id).first_or_404() if action == 'dislike': current_user.dislike_post(post) db.session.commit() likes = post.likes.count() dislikes = post.dislikes.count() result = f"{likes} لایک و {dislikes} دیسلایک" return jsonify(post_id=post_id, state='dislike', result=result) if action == 'undislike': current_user.undislike_post(post) db.session.commit() likes = post.likes.count() dislikes = post.dislikes.count() result = f"{likes} لایک و {dislikes} دیسلایک" return jsonify(post_id=post_id, state='undislike', result=result)
def like_action(post_id, action): post = Post.query.filter_by(id=post_id).first_or_404() if action == 'like': if current_user.has_disliked_post(post): current_user.undislike_post(post) current_user.like_post(post) db.session.commit() if action == 'unlike': current_user.unlike_post(post) db.session.commit() if action == 'dislike': if current_user.has_liked_post(post): current_user.unlike_post(post) current_user.dislike_post(post) db.session.commit() if action == 'undislike': current_user.undislike_post(post) db.session.commit() return redirect(url_for('blog'))