Advertisement
OlexBy

wwwd

May 19th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. from flask import Blueprint, session, jsonify
  2.  
  3. from .models import Comment
  4. from ..auth.models import User
  5. from ..db import db
  6.  
  7. comments_bp = Blueprint('comments', __name__)
  8.  
  9.  
  10. class DeleteRequest:
  11. def delete_comment(self, id):
  12. comment = Comment.query.get_or_404(int(id))
  13. permission = User.is_superuser or User.id == Comment.id
  14. if permission:
  15. db.session.delete(comment)
  16. db.session.commit()
  17.  
  18. def get_comment(self, id):
  19. return db.session.query(Comment).get(int(id))
  20.  
  21.  
  22. @comments_bp.route('/comments/<comment_id>/', methods=['DELETE'])
  23. def deleted_comment(comment_id):
  24. dr = DeleteRequest()
  25. delete = dr.get_comment(comment_id)
  26. if delete is None:
  27. response = jsonify({'status': 'Not found'})
  28. response.status = 404
  29. return response
  30. dr.delete_comment(comment_id)
  31. return jsonify({'status': 'OK'})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement