Advertisement
OlexBy

dfgghgjjk

May 20th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 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. comment_filtered = comment_query.filter(Comment.id == comment_id)
  5. owner = comment_query.join(User).filter(Comment.author_id == User.id).\
  6. filter(Comment.author_id == g.user.id).all()
  7. has_permission = g.user.is_superuser or owner
  8. if has_permission:
  9. result = comment_filtered.delete()
  10. if result:
  11. db.session.commit()
  12. return jsonify({'status': 0})
  13. else:
  14. db.session.rollback()
  15. return jsonify({'msg': 'comment not found', 'status': 1})
  16. else:
  17. return jsonify({'status': 2}), 405
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement