randoz

responses

Jul 14th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. # -*- encoding:utf-8 -*-
  2.  
  3. from django.utils.translation import ugettext_lazy as _
  4.  
  5. from rest_framework import status as status_code
  6. from rest_framework.response import Response
  7.  
  8.  
  9. class DoneResponse(Response):
  10.     """
  11.    Base class for REST Exceptions based on CEH from @vicobits.
  12.    """
  13.     def __init__(self, detail=None, code=None, status=None):
  14.         response = dict()
  15.         response["message"] = detail if detail else _("Operación exitosa !")
  16.         response["code"] = code if code else "success_request"
  17.         _status = status if status else status_code.HTTP_200_OK
  18.         super(DoneResponse, self).__init__(data=response, status=_status)
  19.  
  20.  
  21. class NoContent(Response):
  22.     """
  23.    Base class for REST Exceptions based on CEH from @vicobits.
  24.    """
  25.     def __init__(self, detail=None, code=None, status=None):
  26.         response = dict()
  27.         response["message"] = detail if detail else _("Sin Contenido!")
  28.         response["code"] = code if code else "no_content"
  29.         _status = status if status else status_code.HTTP_200_OK
  30.         super(NoContent, self).__init__(data=response, status=_status)
Advertisement
Add Comment
Please, Sign In to add comment