From aad9289ae9246a94d3d5c50ce2061d5162d38e9f Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Wed, 23 Aug 2017 11:07:56 +0200 Subject: [PATCH] Move `get_filter_fields` to descriptor --- rest_framework/schemas.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/rest_framework/schemas.py b/rest_framework/schemas.py index 6640a8d31..f2e0a689b 100644 --- a/rest_framework/schemas.py +++ b/rest_framework/schemas.py @@ -280,9 +280,9 @@ class APIViewSchemaDescriptor(object): fields = self.get_path_fields(path, method) fields += self.get_serializer_fields(path, method) fields += self.get_pagination_fields(path, method) + fields += self.get_filter_fields(path, method) # TEMP: now we proxy back to the generator - fields += generator.get_filter_fields(path, method, view) if fields and any([field.location in ('form', 'body') for field in fields]): encoding = generator.get_encoding(path, method, view) @@ -442,6 +442,19 @@ class APIViewSchemaDescriptor(object): paginator = view.pagination_class() return paginator.get_schema_fields(view) + def get_filter_fields(self, path, method): + view = self.view + + if not is_list_view(path, method, view): + return [] + + if not getattr(view, 'filter_backends', None): + return [] + + fields = [] + for filter_backend in view.filter_backends: + fields += filter_backend().get_schema_fields(view) + return fields # TODO: Where should this live? # - We import APIView here. So we can't import the descriptor into `views` @@ -650,18 +663,6 @@ class SchemaGenerator(object): return None - def get_filter_fields(self, path, method, view): - if not is_list_view(path, method, view): - return [] - - if not getattr(view, 'filter_backends', None): - return [] - - fields = [] - for filter_backend in view.filter_backends: - fields += filter_backend().get_schema_fields(view) - return fields - # Method for generating the link layout.... def get_keys(self, subpath, method, view):