Commit 011fe8a8 authored by ariovistus's avatar ariovistus
Browse files

Merge pull request #304 from marcgibbons/revert-291-restrict-filtering-for-list-views-2

Revert "Restrict filtering for list views"
parents 89ebabf2 aa7ae202
......@@ -29,30 +29,34 @@ class DocumentationGenerator(object):
api_docs.append({
'description': IntrospectorHelper.get_summary(api['callback']),
'path': api['path'],
'operations': self.get_operations(api),
'operations': self.get_operations(api, apis),
})
return api_docs
def get_introspector(self, api):
def get_introspector(self, api, apis):
path = api['path']
pattern = api['pattern']
callback = api['callback']
if callback.__module__ == 'rest_framework.decorators':
return WrappedAPIViewIntrospector(callback, path, pattern)
elif issubclass(callback, viewsets.ViewSetMixin):
return ViewSetIntrospector(callback, path, pattern)
patterns = [a['pattern'] for a in apis
if a['callback'] == callback]
return ViewSetIntrospector(callback, path, pattern,
patterns=patterns)
else:
return APIViewIntrospector(callback, path, pattern)
def get_operations(self, api):
def get_operations(self, api, apis=None):
"""
Returns docs for the allowed methods of an API endpoint
"""
if apis is None:
apis = [api]
operations = []
introspector = self.get_introspector(api)
introspector = self.get_introspector(api, apis)
for method_introspector in introspector:
if not isinstance(method_introspector, BaseMethodIntrospector) or \
......@@ -213,7 +217,7 @@ class DocumentationGenerator(object):
serializers = set()
for api in apis:
introspector = self.get_introspector(api)
introspector = self.get_introspector(api, apis)
for method_introspector in introspector:
serializer = self._get_method_serializer(method_introspector)
if serializer is not None:
......
......@@ -285,7 +285,7 @@ class BaseMethodIntrospector(object):
body_params = self.build_body_parameters()
form_params = self.build_form_parameters()
query_params = self.build_query_parameters()
if self.method == 'list' and django_filters is not None:
if django_filters is not None:
query_params.extend(
self.build_query_parameters_from_django_filters())
......@@ -581,10 +581,9 @@ class ViewSetIntrospector(BaseViewIntrospector):
self.patterns = patterns or [pattern]
def __iter__(self):
for pattern in self.patterns:
methods = self._resolve_methods(pattern=pattern)
for method in methods:
yield ViewSetMethodIntrospector(self, methods[method], method)
methods = self._resolve_methods()
for method in methods:
yield ViewSetMethodIntrospector(self, methods[method], method)
def methods(self):
stuff = []
......@@ -601,10 +600,10 @@ class ViewSetIntrospector(BaseViewIntrospector):
try:
x = closure_n_code(callback)
callback = get_closure_var(callback)
while getattr(x.code, 'co_name') != 'view':
# lets unwrap!
callback = get_closure_var(callback)
x = closure_n_code(callback)
freevars = x.code.co_freevars
......
......@@ -770,28 +770,19 @@ def get_introspectors(introspector):
def make_viewset_introspector(view_class):
patterns = (
return ViewSetIntrospector(
view_class,
'/api/endpoint/{pk}',
url(
r'^/api/endpoint/?$',
r'^/api/endpoint/(?P<{pk}>[^/]+)$',
view_class.as_view({
'get': 'list',
'post': 'create',
})
),
url(
r'^/api/endpoint/(?P<{pk}>[^/]+)$',
view_class.as_view({
'get': 'retrieve',
'put': 'update',
'patch': 'partial_update',
'delete': 'destroy'
})
))
return ViewSetIntrospector(
view_class,
'/api/endpoint/{pk}',
pattern=patterns[0],
patterns=patterns,
)
)
......@@ -900,14 +891,10 @@ class ViewSetMethodIntrospectorTests(TestCase):
filter_class = UserFilter
class_introspector = self.make_view_introspector(MyViewSet)
list_introspector = get_introspectors(class_introspector)['list']
params = list_introspector.get_parameters()
introspector = get_introspectors(class_introspector)['list']
params = introspector.build_query_parameters_from_django_filters()
self.assertEqual(params,
[{'name': 'pk',
'paramType': 'path',
'required': True,
'type': 'string'},
{'paramType': 'query',
[{'paramType': 'query',
'name': 'username',
'description': 'Username of User',
'dataType': ''
......@@ -919,13 +906,6 @@ class ViewSetMethodIntrospectorTests(TestCase):
'dataType': 'enum'
}
])
detail_introspector = get_introspectors(class_introspector)['retrieve']
self.assertEqual(detail_introspector.get_parameters(),
[{'name': 'pk',
'required': True,
'paramType': 'path',
'type': 'string'}]
)
def test_get_summary_empty(self):
class MyViewSet(ModelViewSet):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment