mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Adjust imports
This commit is contained in:
parent
18575c9f5f
commit
e7f3219fee
|
@ -26,7 +26,8 @@ from rest_framework import views
|
||||||
from rest_framework.compat import NoReverseMatch
|
from rest_framework.compat import NoReverseMatch
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.reverse import reverse
|
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.settings import api_settings
|
||||||
from rest_framework.urlpatterns import format_suffix_patterns
|
from rest_framework.urlpatterns import format_suffix_patterns
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
# The API we expose
|
from .generators import SchemaGenerator
|
||||||
# from .views import get_schema_view
|
from .inspectors import AutoSchema, ManualSchema # noqa
|
||||||
|
|
||||||
|
|
||||||
# Shared function. TODO: move to utils.
|
def get_schema_view(
|
||||||
def is_list_view(path, method, 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'):
|
# Avoid import cycle on APIView
|
||||||
# Viewsets have an explicitly defined action, which we can inspect.
|
from .views import SchemaView
|
||||||
return view.action == 'list'
|
generator = generator_class(
|
||||||
|
title=title, url=url, description=description,
|
||||||
if method.lower() != 'get':
|
urlconf=urlconf, patterns=patterns,
|
||||||
return False
|
)
|
||||||
path_components = path.strip('/').split('/')
|
return SchemaView.as_view(
|
||||||
if path_components and '{' in path_components[-1]:
|
renderer_classes=renderer_classes,
|
||||||
return False
|
schema_generator=generator,
|
||||||
return True
|
public=public,
|
||||||
|
)
|
||||||
|
|
|
@ -14,9 +14,8 @@ from rest_framework.compat import (
|
||||||
from rest_framework.request import clone_request
|
from rest_framework.request import clone_request
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
from rest_framework.utils.model_meta import _get_pk
|
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):
|
def common_path(paths):
|
||||||
|
@ -40,6 +39,8 @@ def is_api_view(callback):
|
||||||
"""
|
"""
|
||||||
Return `True` if the given view callback is a REST framework view/viewset.
|
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)
|
cls = getattr(callback, 'cls', None)
|
||||||
return (cls is not None) and issubclass(cls, APIView)
|
return (cls is not None) and issubclass(cls, APIView)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ from rest_framework.compat import coreapi, coreschema, uritemplate, urlparse
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
from rest_framework.utils import formatting
|
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_]*:')
|
header_regex = re.compile('^[a-zA-Z][0-9A-Za-z_]*:')
|
||||||
|
|
||||||
|
|
16
rest_framework/schemas/utils.py
Normal file
16
rest_framework/schemas/utils.py
Normal file
|
@ -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
|
|
@ -1,6 +1,5 @@
|
||||||
from rest_framework import exceptions, renderers
|
from rest_framework import exceptions, renderers
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.schemas.generators import SchemaGenerator
|
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
|
@ -28,20 +27,3 @@ class SchemaView(APIView):
|
||||||
if schema is None:
|
if schema is None:
|
||||||
raise exceptions.PermissionDenied()
|
raise exceptions.PermissionDenied()
|
||||||
return Response(schema)
|
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,
|
|
||||||
)
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ from rest_framework import exceptions, status
|
||||||
from rest_framework.compat import set_rollback
|
from rest_framework.compat import set_rollback
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.schemas import AutoSchema
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
from rest_framework.utils import formatting
|
from rest_framework.utils import formatting
|
||||||
|
|
||||||
|
@ -113,6 +114,7 @@ class APIView(View):
|
||||||
|
|
||||||
# Mark the view as being included or excluded from schema generation.
|
# Mark the view as being included or excluded from schema generation.
|
||||||
exclude_from_schema = False
|
exclude_from_schema = False
|
||||||
|
schema = AutoSchema()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def as_view(cls, **initkwargs):
|
def as_view(cls, **initkwargs):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user