Merge branch 'master' into localizedfloatfield

This commit is contained in:
kgeorgy 2017-04-24 09:01:37 +02:00 committed by GitHub
commit 377279816b
9 changed files with 39 additions and 19 deletions

View File

@ -54,7 +54,7 @@ There is a live example API for testing purposes, [available here][sandbox].
# Requirements
* Python (2.7, 3.2, 3.3, 3.4, 3.5)
* Django (1.8, 1.9, 1.10)
* Django (1.8, 1.9, 1.10, 1.11)
# Installation

View File

@ -432,8 +432,11 @@ The method should return a rendered HTML string.
## Pagination & schemas
You can also make the filter controls available to the schema autogeneration
that REST framework provides, by implementing a `get_schema_fields()` method,
which should return a list of `coreapi.Field` instances.
that REST framework provides, by implementing a `get_schema_fields()` method. This method should have the following signature:
`get_schema_fields(self, view)`
The method should return a list of `coreapi.Field` instances.
# Third party packages

View File

@ -279,8 +279,11 @@ API responses for list endpoints will now include a `Link` header, instead of in
## Pagination & schemas
You can also make the pagination controls available to the schema autogeneration
that REST framework provides, by implementing a `get_schema_fields()` method,
which should return a list of `coreapi.Field` instances.
that REST framework provides, by implementing a `get_schema_fields()` method. This method should have the following signature:
`get_schema_fields(self, view)`
The method should return a list of `coreapi.Field` instances.
---

View File

@ -88,7 +88,7 @@ continued development by **[signing up for a paid plan][funding]**.
REST framework requires the following:
* Python (2.7, 3.2, 3.3, 3.4, 3.5)
* Django (1.8, 1.9, 1.10)
* Django (1.8, 1.9, 1.10, 1.11)
The following packages are optional:
@ -310,7 +310,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[markdown]: http://pypi.python.org/pypi/Markdown/
[django-filter]: http://pypi.python.org/pypi/django-filter
[django-crispy-forms]: https://github.com/maraujop/django-crispy-forms
[django-guardian]: https://github.com/lukaszb/django-guardian
[django-guardian]: https://github.com/django-guardian/django-guardian
[0.4]: https://github.com/encode/django-rest-framework/tree/0.4.X
[image]: img/quickstart.png
[index]: .

View File

@ -1,6 +1,6 @@
# Optional packages which may be used with REST framework.
markdown==2.6.4
django-guardian==1.4.6
django-guardian==1.4.8
django-filter==1.0.0
coreapi==2.2.4
coreschema==0.0.4

View File

@ -3,10 +3,10 @@ from django.conf.urls import include, url
from rest_framework.renderers import (
CoreJSONRenderer, DocumentationRenderer, SchemaJSRenderer
)
from rest_framework.schemas import get_schema_view
from rest_framework.schemas import SchemaGenerator, get_schema_view
def get_docs_view(title=None, description=None, schema_url=None, public=True):
def get_docs_view(title=None, description=None, schema_url=None, public=True, generator_class=SchemaGenerator):
renderer_classes = [DocumentationRenderer, CoreJSONRenderer]
return get_schema_view(
@ -14,11 +14,12 @@ def get_docs_view(title=None, description=None, schema_url=None, public=True):
url=schema_url,
description=description,
renderer_classes=renderer_classes,
public=public
public=public,
generator_class=generator_class,
)
def get_schemajs_view(title=None, description=None, schema_url=None, public=True):
def get_schemajs_view(title=None, description=None, schema_url=None, public=True, generator_class=SchemaGenerator):
renderer_classes = [SchemaJSRenderer]
return get_schema_view(
@ -26,22 +27,25 @@ def get_schemajs_view(title=None, description=None, schema_url=None, public=True
url=schema_url,
description=description,
renderer_classes=renderer_classes,
public=public
public=public,
generator_class=generator_class,
)
def include_docs_urls(title=None, description=None, schema_url=None, public=True):
def include_docs_urls(title=None, description=None, schema_url=None, public=True, generator_class=SchemaGenerator):
docs_view = get_docs_view(
title=title,
description=description,
schema_url=schema_url,
public=public
public=public,
generator_class=generator_class,
)
schema_js_view = get_schemajs_view(
title=title,
description=description,
schema_url=schema_url,
public=public
public=public,
generator_class=generator_class,
)
urls = [
url(r'^$', docs_view, name='docs-index'),

View File

@ -316,6 +316,7 @@ class DefaultRouter(SimpleRouter):
default_schema_renderers = None
APIRootView = APIRootView
APISchemaView = SchemaView
SchemaGenerator = SchemaGenerator
def __init__(self, *args, **kwargs):
if 'schema_title' in kwargs:
@ -342,7 +343,7 @@ class DefaultRouter(SimpleRouter):
"""
Return a schema root view.
"""
schema_generator = SchemaGenerator(
schema_generator = self.SchemaGenerator(
title=self.schema_title,
url=self.schema_url,
patterns=api_urls

View File

@ -694,11 +694,19 @@ class SchemaView(APIView):
return Response(schema)
def get_schema_view(title=None, url=None, description=None, urlconf=None, renderer_classes=None, public=False):
def get_schema_view(
title=None,
url=None,
description=None,
urlconf=None,
renderer_classes=None,
public=False,
generator_class=SchemaGenerator,
):
"""
Return a schema view.
"""
generator = SchemaGenerator(title=title, url=url, description=description, urlconf=urlconf)
generator = generator_class(title=title, url=url, description=description, urlconf=urlconf)
return SchemaView.as_view(
renderer_classes=renderer_classes,
schema_generator=generator,

View File

@ -95,6 +95,7 @@ setup(
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',