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(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 dislike_action(post_id, action): post = Post.query.get_or_404(post_id) if action == 'dislike': current_user.dislike_post(post) current_user.unlike_post(post) db.session.commit() if action == 'undislike': current_user.undislike_post(post) db.session.commit() return redirect(request.referrer)
def like_post(post_id: int, is_like): if bool(is_like): current_user.like_post(post_id) else: current_user.dislike_post(post_id) post = Post.query.get(post_id) post_likes = { 'likes': post.like_count, 'dislikes': post.dislike_count, 'views': post.view_count, 'comments': post.comment_count } return jsonify(post_likes)
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'))
def likes(): postId = request.form['postId'] action = request.form['action'] print(postId) if postId and action: post = Post.query.filter_by(id=int(postId)).first_or_404() if action == 'likes': current_user.like_post(post) db.session.commit() return jsonify({'status': 'OK', 'id': postId, 'action': action}) if action == 'dislikes': current_user.dislike_post(post) db.session.commit() return jsonify({'status': 'OK', 'id': postId, 'action': action}) return jsonify({'error': 'error xxx'}) """if action == 'like':