Remove explicit handling of 'OPTIONS' method, just raise the response, rather than returning it.

This commit is contained in:
Tom Christie 2012-01-11 14:48:22 +00:00
parent ac51210594
commit 42563d9fbc

View File

@ -119,7 +119,6 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
""" """
self.headers[field] = value self.headers[field] = value
# Note: session based authentication is explicitly CSRF validated, # Note: session based authentication is explicitly CSRF validated,
# all other authentication is CSRF exempt. # all other authentication is CSRF exempt.
@csrf_exempt @csrf_exempt
@ -153,13 +152,8 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
else: else:
response = Response(status.HTTP_204_NO_CONTENT) response = Response(status.HTTP_204_NO_CONTENT)
if request.method == 'OPTIONS': # Pre-serialize filtering (eg filter complex objects into natively serializable types)
# do not filter the response for HTTP OPTIONS, else the response fields are lost, response.cleaned_content = self.filter_response(response.raw_content)
# as they do not correspond with model fields
response.cleaned_content = response.raw_content
else:
# Pre-serialize filtering (eg filter complex objects into natively serializable types)
response.cleaned_content = self.filter_response(response.raw_content)
except ErrorResponse, exc: except ErrorResponse, exc:
response = exc.response response = exc.response
@ -179,7 +173,10 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
for name, field in form.fields.iteritems(): for name, field in form.fields.iteritems():
field_name_types[name] = field.__class__.__name__ field_name_types[name] = field.__class__.__name__
response_obj['fields'] = field_name_types response_obj['fields'] = field_name_types
return response_obj # Note 'ErrorResponse' is misleading, it's just any response
# that should be rendered and returned immediately, without any
# response filtering.
raise ErrorResponse(status.HTTP_200_OK, response_obj)
class ModelView(View): class ModelView(View):