Advertisement
OlexBy

dssdddfffffggg

May 22nd, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. @comments_bp.route('/comments/<int:comment_id>/', methods=['DELETE'])
  2. def delete_comment(comment_id):
  3. comment_query = db.session.query(Comment)
  4. user_sq = comment_query.join(User).filter(Comment.author_id == User.id).\
  5. filter(Comment.author_id == g.user.id).subquery()
  6. has_permission = comment_query.filter(or_(g.user.is_superuser is True, user_sq))
  7. comment_filtered = has_permission.filter(Comment.id == comment_id)
  8. result = comment_filtered.delete(synchronize_session='fetch')
  9. if result:
  10. db.session.commit()
  11. return jsonify({'status': 0})
  12. else:
  13. db.session.rollback()
  14. return jsonify({'msg': 'comment not found', 'status': 1})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement