diff --git a/rest_framework/schemas/generators.py b/rest_framework/schemas/generators.py index 4b6d82a14..8c552d690 100644 --- a/rest_framework/schemas/generators.py +++ b/rest_framework/schemas/generators.py @@ -29,8 +29,8 @@ def is_api_view(callback): """ # Avoid import cycle on APIView from rest_framework.views import APIView - cls = getattr(callback, 'cls', None) - return (cls is not None) and issubclass(cls, APIView) + view_class = getattr(callback, 'view_class', None) + return (view_class is not None) and issubclass(view_class, APIView) def endpoint_ordering(endpoint): @@ -117,11 +117,11 @@ class EndpointEnumerator: if not is_api_view(callback): return False # Ignore anything except REST framework views. - if callback.cls.schema is None: + if callback.view_class.schema is None: return False - if 'schema' in callback.initkwargs: - if callback.initkwargs['schema'] is None: + if 'schema' in callback.view_initkwargs: + if callback.view_initkwargs['schema'] is None: return False if path.endswith('.{format}') or path.endswith('.{format}/'): @@ -135,10 +135,10 @@ class EndpointEnumerator: """ if hasattr(callback, 'actions'): actions = set(callback.actions) - http_method_names = set(callback.cls.http_method_names) + http_method_names = set(callback.view_class.http_method_names) methods = [method.upper() for method in actions & http_method_names] else: - methods = callback.cls().allowed_methods + methods = callback.view_class().allowed_methods return [method for method in methods if method not in ('OPTIONS', 'HEAD')] @@ -188,7 +188,7 @@ class BaseSchemaGenerator(object): """ Given a callback, return an actual view instance. """ - view = callback.cls(**getattr(callback, 'initkwargs', {})) + view = callback.view_class(**getattr(callback, 'view_initkwargs', {})) view.args = () view.kwargs = {} view.format_kwarg = None diff --git a/rest_framework/utils/breadcrumbs.py b/rest_framework/utils/breadcrumbs.py index 54990e9f6..559d3afe8 100644 --- a/rest_framework/utils/breadcrumbs.py +++ b/rest_framework/utils/breadcrumbs.py @@ -21,13 +21,13 @@ def get_breadcrumbs(url, request=None): else: # Check if this is a REST framework view, # and if so add it to the breadcrumbs - cls = getattr(view, 'cls', None) - initkwargs = getattr(view, 'initkwargs', {}) - if cls is not None and issubclass(cls, APIView): + view_class = getattr(view, 'view_class', None) + initkwargs = getattr(view, 'view_initkwargs', {}) + if view_class is not None and issubclass(view_class, APIView): # Don't list the same view twice in a row. # Probably an optional trailing slash. if not seen or seen[-1] != view: - c = cls(**initkwargs) + c = view_class(**initkwargs) name = c.get_view_name() insert_url = preserve_builtin_query_params(prefix + url, request) breadcrumbs_list.insert(0, (name, insert_url)) diff --git a/rest_framework/views.py b/rest_framework/views.py index 69db053d6..e3c86174b 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -136,8 +136,8 @@ class APIView(View): cls.queryset._fetch_all = force_evaluation view = super().as_view(**initkwargs) - view.cls = cls - view.initkwargs = initkwargs + view.view_class = cls + view.view_initkwargs = initkwargs # Note: session based authentication is explicitly CSRF validated, # all other authentication is CSRF exempt. diff --git a/rest_framework/viewsets.py b/rest_framework/viewsets.py index d94c81df4..17fccb552 100644 --- a/rest_framework/viewsets.py +++ b/rest_framework/viewsets.py @@ -123,8 +123,8 @@ class ViewSetMixin: # We need to set these on the view function, so that breadcrumb # generation can pick out these bits of information from a # resolved URL. - view.cls = cls - view.initkwargs = initkwargs + view.view_class = cls + view.view_initkwargs = initkwargs view.actions = actions return csrf_exempt(view) diff --git a/tests/schemas/test_get_schema_view.py b/tests/schemas/test_get_schema_view.py index f582c6495..c9838b156 100644 --- a/tests/schemas/test_get_schema_view.py +++ b/tests/schemas/test_get_schema_view.py @@ -9,12 +9,12 @@ class GetSchemaViewTests(TestCase): """For the get_schema_view() helper.""" def test_openapi(self): schema_view = get_schema_view(title="With OpenAPI") - assert isinstance(schema_view.initkwargs['schema_generator'], openapi.SchemaGenerator) - assert renderers.OpenAPIRenderer in schema_view.cls().renderer_classes + assert isinstance(schema_view.view_initkwargs['schema_generator'], openapi.SchemaGenerator) + assert renderers.OpenAPIRenderer in schema_view.view_class().renderer_classes @pytest.mark.skipif(not coreapi.coreapi, reason='coreapi is not installed') def test_coreapi(self): with override_settings(REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.AutoSchema'}): schema_view = get_schema_view(title="With CoreAPI") - assert isinstance(schema_view.initkwargs['schema_generator'], coreapi.SchemaGenerator) - assert renderers.CoreAPIOpenAPIRenderer in schema_view.cls().renderer_classes + assert isinstance(schema_view.view_initkwargs['schema_generator'], coreapi.SchemaGenerator) + assert renderers.CoreAPIOpenAPIRenderer in schema_view.view_class().renderer_classes diff --git a/tests/test_decorators.py b/tests/test_decorators.py index e10f0e5c5..0e836f6be 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -164,7 +164,7 @@ class DecoratorTestCase(TestCase): def view(request): return Response({}) - assert isinstance(view.cls.schema, CustomSchema) + assert isinstance(view.view_class.schema, CustomSchema) class ActionDecoratorTestCase(TestCase): diff --git a/tests/test_routers.py b/tests/test_routers.py index ff927ff33..2b277b878 100644 --- a/tests/test_routers.py +++ b/tests/test_routers.py @@ -470,18 +470,18 @@ class TestViewInitkwargs(URLPatternsTestCase, TestCase): def test_suffix(self): match = resolve('/example/notes/') - initkwargs = match.func.initkwargs + initkwargs = match.func.view_initkwargs assert initkwargs['suffix'] == 'List' def test_detail(self): match = resolve('/example/notes/') - initkwargs = match.func.initkwargs + initkwargs = match.func.view_initkwargs assert not initkwargs['detail'] def test_basename(self): match = resolve('/example/notes/') - initkwargs = match.func.initkwargs + initkwargs = match.func.view_initkwargs assert initkwargs['basename'] == 'routertestmodel'