X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/da8442aa10f031739977a5ab296538b4e32bf284..22aac0da99594406b261f14c135812c855c196ef:/apps/api/response.py diff --git a/apps/api/response.py b/apps/api/response.py deleted file mode 100644 index 46750158..00000000 --- a/apps/api/response.py +++ /dev/null @@ -1,107 +0,0 @@ -# -*- encoding: utf-8 -*- - -__author__= "Łukasz Rekucki" -__date__ = "$2009-09-26 00:32:18$" -__doc__ = "Extensible HTTP Responses." - -from django.http import HttpResponse -from django.utils import simplejson as json - -MIME_PLAIN = 'text/plain' -MIME_JSON = 'application/json' - -class ResponseObject(object): - - def __init__(self, code, mimetype=MIME_JSON): - self._code = code - self._mime = mimetype - - def django_response(self, body=None): - if body is None: - data = '' - elif self._mime == MIME_JSON: - data = json.dumps(body, default=lambda o: repr(o) ) - else: - # data = u"%s\n%s" % (self.MESSAGE, unicode(body)) - data = unicode(body).encode('utf-8') - - return HttpResponse(content=data, status=self._code, \ - content_type=self._mime+'; charset=utf-8' ) - -class SuccessAllOk(ResponseObject): - def __init__(self, **kwargs): - ResponseObject.__init__(self, 200, **kwargs) - -class EntityCreated(ResponseObject): - - def __init__(self, **kwargs): - ResponseObject.__init__(self, 201, **kwargs) - - def django_response(self, url, body): - response = ResponseObject.django_response(self, body) - response['Location'] = url - return response - -class RequestAccepted(ResponseObject): - - def __init__(self, **kwargs): - ResponseObject.__init__(self, 202, **kwargs) - - def django_response(self, ticket_status, ticket_uri): - return ResponseObject.django_response(self, { - 'result': 'accepted', - 'status': ticket_status, - 'refer_to': ticket_uri }) - -class SuccessNoContent(ResponseObject): - - def __init__(self, **kwargs): - ResponseObject.__init__(self, 204, **kwargs) - - def django_response(self): - return ResponseObject.django_response(self, body=None) - -# -# Client errors -# - -class BadRequest(ResponseObject): - - def __init__(self, **kwargs): - ResponseObject.__init__(self, 400, **kwargs) - -class AccessDenied(ResponseObject): - - def __init__(self, **kwargs): - ResponseObject.__init__(self, 403, **kwargs) - - -class EntityNotFound(ResponseObject): - - def __init__(self, **kwargs): - ResponseObject.__init__(self, 404, **kwargs) - -class EntityGone(ResponseObject): - - def __init__(self, **kwargs): - ResponseObject.__init__(self, 410, **kwargs) - - -class EntityConflict(ResponseObject): - - def __init__(self, **kwargs): - ResponseObject.__init__(self, 409, **kwargs) - - -# -# Server side errors -# -class InternalError(ResponseObject): - - def __init__(self, **kwargs): - ResponseObject.__init__(self, 500, **kwargs) - -class NotImplemented(ResponseObject): - - def __init__(self, **kwargs): - ResponseObject.__init__(self, 501, **kwargs) \ No newline at end of file