aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/generics.py
diff options
context:
space:
mode:
authorTom Christie2014-09-24 14:09:49 +0100
committerTom Christie2014-09-24 14:09:49 +0100
commitf4b1dcb167be0bbdaae2cc2a92f651536896dc16 (patch)
tree855df19d2a09da4329274db4bc56d89b342df036 /rest_framework/generics.py
parentaa84432f9b40849fb677d9fed803098fd392f881 (diff)
downloaddjango-rest-framework-f4b1dcb167be0bbdaae2cc2a92f651536896dc16.tar.bz2
OPTIONS support
Diffstat (limited to 'rest_framework/generics.py')
-rw-r--r--rest_framework/generics.py51
1 files changed, 1 insertions, 50 deletions
diff --git a/rest_framework/generics.py b/rest_framework/generics.py
index eb6b64ef..f49b0a43 100644
--- a/rest_framework/generics.py
+++ b/rest_framework/generics.py
@@ -4,13 +4,11 @@ Generic views that provide commonly needed behaviour.
from __future__ import unicode_literals
from django.db.models.query import QuerySet
-from django.core.exceptions import PermissionDenied
from django.core.paginator import Paginator, InvalidPage
from django.http import Http404
from django.shortcuts import get_object_or_404 as _get_object_or_404
from django.utils.translation import ugettext as _
-from rest_framework import views, mixins, exceptions
-from rest_framework.request import clone_request
+from rest_framework import views, mixins
from rest_framework.settings import api_settings
@@ -249,53 +247,6 @@ class GenericAPIView(views.APIView):
return obj
- # The following are placeholder methods,
- # and are intended to be overridden.
- #
- # The are not called by GenericAPIView directly,
- # but are used by the mixin methods.
- def metadata(self, request):
- """
- Return a dictionary of metadata about the view.
- Used to return responses for OPTIONS requests.
-
- We override the default behavior, and add some extra information
- about the required request body for POST and PUT operations.
- """
- ret = super(GenericAPIView, self).metadata(request)
-
- actions = {}
- for method in ('PUT', 'POST'):
- if method not in self.allowed_methods:
- continue
-
- cloned_request = clone_request(request, method)
- try:
- # Test global permissions
- self.check_permissions(cloned_request)
- # Test object permissions
- if method == 'PUT':
- try:
- self.get_object()
- except Http404:
- # Http404 should be acceptable and the serializer
- # metadata should be populated. Except this so the
- # outer "else" clause of the try-except-else block
- # will be executed.
- pass
- except (exceptions.APIException, PermissionDenied):
- pass
- else:
- # If user has appropriate permissions for the view, include
- # appropriate metadata about the fields that should be supplied.
- serializer = self.get_serializer()
- actions[method] = serializer.metadata()
-
- if actions:
- ret['actions'] = actions
-
- return ret
-
# Concrete view classes that provide method handlers
# by composing the mixin classes with the base view.