Skip to content

Commit

Permalink
Adjust imports
Browse files Browse the repository at this point in the history
  • Loading branch information
carltongibson committed Sep 6, 2017
1 parent 2b69550 commit 1a2888a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 37 deletions.
3 changes: 2 additions & 1 deletion rest_framework/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
from rest_framework.compat import NoReverseMatch
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework.schemas import SchemaGenerator, SchemaView
from rest_framework.schemas import SchemaGenerator
from rest_framework.schemas.views import SchemaView
from rest_framework.settings import api_settings
from rest_framework.urlpatterns import format_suffix_patterns

Expand Down
32 changes: 17 additions & 15 deletions rest_framework/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# The API we expose
# from .views import get_schema_view
from .generators import SchemaGenerator
from .inspectors import AutoSchema, ManualSchema # noqa


# Shared function. TODO: move to utils.
def is_list_view(path, method, view):
def get_schema_view(
title=None, url=None, description=None, urlconf=None, renderer_classes=None,
public=False, patterns=None, generator_class=SchemaGenerator):
"""
Return True if the given path/method appears to represent a list view.
Return a schema view.
"""
if hasattr(view, 'action'):
# Viewsets have an explicitly defined action, which we can inspect.
return view.action == 'list'

if method.lower() != 'get':
return False
path_components = path.strip('/').split('/')
if path_components and '{' in path_components[-1]:
return False
return True
# Avoid import cycle on APIView
from .views import SchemaView
generator = generator_class(
title=title, url=url, description=description,
urlconf=urlconf, patterns=patterns,
)
return SchemaView.as_view(
renderer_classes=renderer_classes,
schema_generator=generator,
public=public,
)
5 changes: 3 additions & 2 deletions rest_framework/schemas/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
from rest_framework.request import clone_request
from rest_framework.settings import api_settings
from rest_framework.utils.model_meta import _get_pk
from rest_framework.views import APIView

from . import is_list_view
from .utils import is_list_view


def common_path(paths):
Expand All @@ -40,6 +39,8 @@ def is_api_view(callback):
"""
Return `True` if the given view callback is a REST framework view/viewset.
"""
# 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)

Expand Down
2 changes: 1 addition & 1 deletion rest_framework/schemas/inspectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from rest_framework.settings import api_settings
from rest_framework.utils import formatting

from . import is_list_view
from .utils import is_list_view

header_regex = re.compile('^[a-zA-Z][0-9A-Za-z_]*:')

Expand Down
16 changes: 16 additions & 0 deletions rest_framework/schemas/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


def is_list_view(path, method, view):
"""
Return True if the given path/method appears to represent a list view.
"""
if hasattr(view, 'action'):
# Viewsets have an explicitly defined action, which we can inspect.
return view.action == 'list'

if method.lower() != 'get':
return False
path_components = path.strip('/').split('/')
if path_components and '{' in path_components[-1]:
return False
return True
18 changes: 0 additions & 18 deletions rest_framework/schemas/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from rest_framework import exceptions, renderers
from rest_framework.response import Response
from rest_framework.schemas.generators import SchemaGenerator
from rest_framework.settings import api_settings
from rest_framework.views import APIView

Expand Down Expand Up @@ -28,20 +27,3 @@ def get(self, request, *args, **kwargs):
if schema is None:
raise exceptions.PermissionDenied()
return Response(schema)


def get_schema_view(
title=None, url=None, description=None, urlconf=None, renderer_classes=None,
public=False, patterns=None, generator_class=SchemaGenerator):
"""
Return a schema view.
"""
generator = generator_class(
title=title, url=url, description=description,
urlconf=urlconf, patterns=patterns,
)
return SchemaView.as_view(
renderer_classes=renderer_classes,
schema_generator=generator,
public=public,
)
2 changes: 2 additions & 0 deletions rest_framework/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from rest_framework.compat import set_rollback
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.schemas import AutoSchema
from rest_framework.settings import api_settings
from rest_framework.utils import formatting

Expand Down Expand Up @@ -113,6 +114,7 @@ class APIView(View):

# Mark the view as being included or excluded from schema generation.
exclude_from_schema = False
schema = AutoSchema()

@classmethod
def as_view(cls, **initkwargs):
Expand Down

0 comments on commit 1a2888a

Please sign in to comment.