aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLudwig Kraatz2012-11-13 18:07:38 +0100
committerLudwig Kraatz2012-11-13 18:07:38 +0100
commit573de11b233a85347456a4d7e50fd7345d13db03 (patch)
tree961e9d5038e240bd7881ee620ca9fec410d957d4
parentcc55a7b64310cdd4b8b96e8270a48fd994ede90c (diff)
downloaddjango-rest-framework-573de11b233a85347456a4d7e50fd7345d13db03.tar.bz2
changed buggy response + code ploishing
reponse didnt handle any headers at all. Accepts now a dict of headers and sets those properly
-rw-r--r--rest_framework/mixins.py11
-rw-r--r--rest_framework/response.py5
2 files changed, 7 insertions, 9 deletions
diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py
index f54b5b1f..eddd8f49 100644
--- a/rest_framework/mixins.py
+++ b/rest_framework/mixins.py
@@ -25,16 +25,11 @@ class CreateModelMixin(object):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def get_success_headers(self,serializer):
- headers = []
- identity_field = identity_name = None
+ headers = {}
for name,field in serializer.fields.iteritems():
if isinstance(field,HyperlinkedIdentityField):
- identity_name, identity_field = name, field
- if identity_field:
- #identity_field.initialize(serializer,"url")
- headers.append(
- ("Location",identity_field.field_to_native(self.object,identity_name))
- )
+ headers["Location"] = field.field_to_native(self.object,name)
+ break
return headers
def pre_save(self, obj):
diff --git a/rest_framework/response.py b/rest_framework/response.py
index 0de01204..88f0019f 100644
--- a/rest_framework/response.py
+++ b/rest_framework/response.py
@@ -20,9 +20,12 @@ class Response(SimpleTemplateResponse):
"""
super(Response, self).__init__(None, status=status)
self.data = data
- self.headers = headers and headers[:] or []
self.template_name = template_name
self.exception = exception
+
+ if headers:
+ for name,value in headers.iteritems():
+ self[name] = value
@property
def rendered_content(self):