elif self._mime == MIME_JSON:
data = json.dumps(body, default=lambda o: repr(o) )
else:
- data = u"%s\n%s" % (self.MESSAGE, unicode(self._info))
- data = data.encode('utf-8')
+ # 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' )
def django_response(self):
return ResponseObject.django_response(self, body=None)
-
#
# Client errors
#
def __init__(self, **kwargs):
ResponseObject.__init__(self, 403, **kwargs)
-
- def django_response(self, reason):
- return ResponseObject.django_response(self, \
- body={'reason': reason})
+
class EntityNotFound(ResponseObject):
ResponseObject.__init__(self, 409, **kwargs)
-def validate_form(formclass, source='GET'):
- from functools import wraps
-
- def decorator(func):
- @wraps(func)
- def decorated(self, request, *args, **kwargs):
- form = formclass(getattr(request, source), request.FILES)
-
- if not form.is_valid():
- errorlist = [{'field': k, 'errors': e} for k,e in form.errors]
- return BadRequest().django_response(errorlist)
-
- return func(self, request, form, *args, **kwargs)
- return decorated
- return decorator
-
-
+#
+# 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