Advertisement
OlexBy

443

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