changed buggy response + code ploishing

reponse didnt handle any headers at all. Accepts now a dict of headers
and sets those properly
This commit is contained in:
Ludwig Kraatz 2012-11-13 18:07:38 +01:00
parent cc55a7b643
commit 573de11b23
2 changed files with 7 additions and 9 deletions

View File

@ -25,16 +25,11 @@ class CreateModelMixin(object):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get_success_headers(self,serializer): def get_success_headers(self,serializer):
headers = [] headers = {}
identity_field = identity_name = None
for name,field in serializer.fields.iteritems(): for name,field in serializer.fields.iteritems():
if isinstance(field,HyperlinkedIdentityField): if isinstance(field,HyperlinkedIdentityField):
identity_name, identity_field = name, field headers["Location"] = field.field_to_native(self.object,name)
if identity_field: break
#identity_field.initialize(serializer,"url")
headers.append(
("Location",identity_field.field_to_native(self.object,identity_name))
)
return headers return headers
def pre_save(self, obj): def pre_save(self, obj):

View File

@ -20,10 +20,13 @@ class Response(SimpleTemplateResponse):
""" """
super(Response, self).__init__(None, status=status) super(Response, self).__init__(None, status=status)
self.data = data self.data = data
self.headers = headers and headers[:] or []
self.template_name = template_name self.template_name = template_name
self.exception = exception self.exception = exception
if headers:
for name,value in headers.iteritems():
self[name] = value
@property @property
def rendered_content(self): def rendered_content(self):
renderer = getattr(self, 'accepted_renderer', None) renderer = getattr(self, 'accepted_renderer', None)