def post_like(id): post = Post.query.get_or_404(id) if request.method == "POST": if current_user.is_like_post(post): res = Like.query.filter_by(post_id=post.id).filter_by(user_id=current_user.id).first() if res: res.liked = False db.session.add(res) else: res = Like.query.filter_by(post_id=post.id).filter_by(user_id=current_user.id).first() if res: res.liked = True db.session.add(res) else: res = Like(post=post, user=current_user._get_current_object(), liked=True) db.session.add(res) db.session.commit() return redirect(url_for("main.index"))
def post_like(id): post = Post.query.get_or_404(id) if request.method == 'GET': if current_user.is_like_post(post): res = Like.query.filter_by(post_id=post.id).filter_by(user_id = current_user.id).first() if res: res.liked = False db.session.add(res) else: res = Like.query.filter_by(post_id=post.id).filter_by(user_id = current_user.id).first() if res: res.liked = True db.session.add(res) else: res = Like(post=post, user=current_user._get_current_object(),liked=True) db.session.add(res) db.session.commit() return '{"status": "ok"}'
def post_like(id, redir): post = Post.query.get_or_404(id) page = request.args.get('page', 1, type = int) if current_user.is_like_post(post): like = Like.query.filter_by(post_id = post.id).first() db.session.delete(like) else: like = Like(post = post, author = current_user._get_current_object()) db.session.add(like) db.session.commit() redir_frament = ''.join(('post', str(post.id))) if redir == '.index': return redirect(url_for('.index', page = page, _anchor=redir_frament)) elif redir == '.post': return redirect(url_for('.post', id = post.id)) elif redir == '.category': return redirect(url_for('.category', page = page, id = post.category.id, _anchor=redir_frament)) elif redir == '.user': return redirect(url_for('.user', username = current_user._get_current_object().username, _anchor=redir_frament))
def post_like(id): post = Post.query.get_or_404(id) if request.method == 'POST': if current_user.is_like_post(post): res = Like.query.filter_by(post_id=post.id).filter_by( user_id=current_user.id).first() if res: res.liked = False db.session.add(res) else: res = Like.query.filter_by(post_id=post.id).filter_by( user_id=current_user.id).first() if res: res.liked = True db.session.add(res) else: res = Like(post=post, user=current_user._get_current_object(), liked=True) db.session.add(res) db.session.commit() return redirect(url_for('main.index'))