mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-30 02:13:29 +03:00
abstract away allowed actions and methods, and use a set for faster membership checks
This commit is contained in:
parent
ea1da76196
commit
d3f8ae4a5d
|
@ -11,7 +11,7 @@ from rest_framework.settings import api_settings
|
||||||
|
|
||||||
from .generators import BaseSchemaGenerator
|
from .generators import BaseSchemaGenerator
|
||||||
from .inspectors import ViewInspector
|
from .inspectors import ViewInspector
|
||||||
from .utils import get_pk_description, is_list_view
|
from .utils import get_pk_description, is_list_view, ALLOW_FILTER_ACTIONS, ALLOW_FILTER_METHODS
|
||||||
|
|
||||||
|
|
||||||
def common_path(paths):
|
def common_path(paths):
|
||||||
|
@ -522,9 +522,9 @@ class AutoSchema(ViewInspector):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if hasattr(self.view, 'action'):
|
if hasattr(self.view, 'action'):
|
||||||
return self.view.action in ["list", "retrieve", "update", "partial_update", "destroy"]
|
return self.view.action in ALLOW_FILTER_ACTIONS
|
||||||
|
|
||||||
return method.lower() in ["get", "put", "patch", "delete"]
|
return method.lower() in ALLOW_FILTER_METHODS
|
||||||
|
|
||||||
def get_filter_fields(self, path, method):
|
def get_filter_fields(self, path, method):
|
||||||
if not self._allows_filters(path, method):
|
if not self._allows_filters(path, method):
|
||||||
|
|
|
@ -18,7 +18,7 @@ from rest_framework.settings import api_settings
|
||||||
|
|
||||||
from .generators import BaseSchemaGenerator
|
from .generators import BaseSchemaGenerator
|
||||||
from .inspectors import ViewInspector
|
from .inspectors import ViewInspector
|
||||||
from .utils import get_pk_description, is_list_view
|
from .utils import get_pk_description, is_list_view, ALLOW_FILTER_ACTIONS, ALLOW_FILTER_METHODS
|
||||||
|
|
||||||
|
|
||||||
class SchemaGenerator(BaseSchemaGenerator):
|
class SchemaGenerator(BaseSchemaGenerator):
|
||||||
|
@ -320,8 +320,8 @@ class AutoSchema(ViewInspector):
|
||||||
if getattr(self.view, 'filter_backends', None) is None:
|
if getattr(self.view, 'filter_backends', None) is None:
|
||||||
return False
|
return False
|
||||||
if hasattr(self.view, 'action'):
|
if hasattr(self.view, 'action'):
|
||||||
return self.view.action in ["list", "retrieve", "update", "partial_update", "destroy"]
|
return self.view.action in ALLOW_FILTER_ACTIONS
|
||||||
return method.lower() in ["get", "put", "patch", "delete"]
|
return method.lower() in ALLOW_FILTER_METHODS
|
||||||
|
|
||||||
def get_pagination_parameters(self, path, method):
|
def get_pagination_parameters(self, path, method):
|
||||||
view = self.view
|
view = self.view
|
||||||
|
|
|
@ -39,3 +39,6 @@ def get_pk_description(model, model_field):
|
||||||
value_type=value_type,
|
value_type=value_type,
|
||||||
name=model._meta.verbose_name,
|
name=model._meta.verbose_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ALLOW_FILTER_ACTIONS = {"list", "retrieve", "update", "partial_update", "destroy"}
|
||||||
|
ALLOW_FILTER_METHODS = {"get", "put", "patch", "delete"}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user