Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
08c7853
Start test case
lovelydinosaur Aug 1, 2016
5abac93
Merge branch 'master' into requests-client
lovelydinosaur Aug 12, 2016
3d1fff3
Added 'requests' test client
lovelydinosaur Aug 15, 2016
e76ca6e
Address typos
lovelydinosaur Aug 15, 2016
6ede654
Graceful fallback if requests is not installed.
lovelydinosaur Aug 17, 2016
049a39e
Add cookie support
lovelydinosaur Aug 17, 2016
64e19c7
Tests for auth and CSRF
lovelydinosaur Aug 17, 2016
da47c34
Py3 compat
lovelydinosaur Aug 17, 2016
5311769
py3 compat
lovelydinosaur Aug 17, 2016
0b3db02
py3 compat
lovelydinosaur Aug 17, 2016
0cc3f50
Add get_requests_client
lovelydinosaur Aug 18, 2016
e4f6928
Added SchemaGenerator.should_include_link
lovelydinosaur Sep 2, 2016
46b9e4e
add settings for html cutoff on related fields
Aug 22, 2016
a556b9c
Router doesn't work if prefix is blank, though project urls.py handle…
c17r Sep 14, 2016
8609c9c
Fix Django 1.10 to-many deprecation
Sep 15, 2016
197b63a
Add django.core.urlresolvers compatibility
Sep 15, 2016
bb37cb7
Update django-filter & django-guardian
Sep 15, 2016
a372a8e
Check for empty router prefix; adjust URL accordingly
c17r Sep 15, 2016
a084924
Fix misc django deprecations
Sep 15, 2016
3bfb0b7
Use TOC extension instead of header
Sep 15, 2016
3bdb0e9
Fix deprecations for py3k
Sep 16, 2016
a0a8b98
Add py3k compatibility to is_simple_callable
Sep 22, 2016
adcf653
Add is_simple_callable tests
Sep 22, 2016
b3afcb2
Drop python 3.2 support (EOL, Dropped by Django)
Sep 22, 2016
b516712
schema_renderers= should *set* the renderers, not append to them.
lovelydinosaur Sep 28, 2016
37b3475
API client (#4424)
lovelydinosaur Sep 29, 2016
c2cec78
Merge master
lovelydinosaur Sep 29, 2016
a60ef8c
Merge branch 'schema-renderers-only-for-root-view' into version-3-5
lovelydinosaur Sep 29, 2016
61b1189
Fix release notes
lovelydinosaur Sep 29, 2016
bc9b522
Merge branch 'rpkilby-fix-simple-callable' into version-3-5
lovelydinosaur Sep 29, 2016
9a4ed1b
Merge branch 'should_include_link' into version-3-5
lovelydinosaur Sep 29, 2016
24bf382
Merge branch 'html_cutoff_settings' of https://github.com/MobileWorks…
lovelydinosaur Sep 29, 2016
f455c67
Merge branch 'MobileWorks-html_cutoff_settings' into version-3-5
lovelydinosaur Sep 29, 2016
b689a3b
Add note about 'User account is disabled.' vs 'Unable to log in'
lovelydinosaur Sep 29, 2016
818ab45
Merge branch 'fix-deprecations' of https://github.com/rpkilby/django-…
lovelydinosaur Sep 29, 2016
ee2b165
Merge branch 'rpkilby-fix-deprecations' into version-3-5
lovelydinosaur Sep 29, 2016
c427144
Merge branch 'router-empty-prefix' of https://github.com/c17r/django-…
lovelydinosaur Sep 29, 2016
49ce3d6
Merge branch 'c17r-router-empty-prefix' into version-3-5
lovelydinosaur Sep 29, 2016
c3a9538
Clean up schema generation (#4527)
lovelydinosaur Sep 30, 2016
4ad5256
Handle multiple methods on custom action (#4529)
lovelydinosaur Sep 30, 2016
8044d38
RequestsClient, CoreAPIClient
lovelydinosaur Oct 4, 2016
a8501f7
exclude_from_schema
lovelydinosaur Oct 5, 2016
cd826ce
Added 'get_schema_view()' shortcut
lovelydinosaur Oct 5, 2016
7e3a3a4
Added schema descriptions
lovelydinosaur Oct 5, 2016
1084dca
Better descriptions for schemas
lovelydinosaur Oct 5, 2016
7edee80
Add type annotation to schema generation
lovelydinosaur Oct 6, 2016
b44ab76
Coerce schema 'pk' in path to actual field name
lovelydinosaur Oct 6, 2016
0724420
Deprecations move into assertion errors
lovelydinosaur Oct 6, 2016
3eb7fe6
Use get_schema_view in tests
lovelydinosaur Oct 7, 2016
5858168
Updte CoreJSON media type
lovelydinosaur Oct 7, 2016
69b4acd
Handle schema structure correctly when path prefixs exist. Closes #4401
lovelydinosaur Oct 7, 2016
fcf932f
Add PendingDeprecation to Router schema generation.
lovelydinosaur Oct 7, 2016
18aebbb
Added SCHEMA_COERCE_PATH_PK and SCHEMA_COERCE_METHOD_NAMES
lovelydinosaur Oct 10, 2016
3f3213b
Renamed and documented 'get_schema_fields' interface.
lovelydinosaur Oct 10, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Renamed and documented 'get_schema_fields' interface.
  • Loading branch information
lovelydinosaur committed Oct 10, 2016
commit 3f3213b5d04149cdf852a36397f4626502862182
6 changes: 6 additions & 0 deletions docs/api-guide/filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ Generic filters may also present an interface in the browsable API. To do so you

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.

# Third party packages

The following third party packages provide additional filter implementations.
Expand Down
6 changes: 6 additions & 0 deletions docs/api-guide/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ To have your custom pagination class be used by default, use the `DEFAULT_PAGINA

API responses for list endpoints will now include a `Link` header, instead of including the pagination links as part of the body of the response, for example:

## 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.

---

![Link Header][link-header]
Expand Down
28 changes: 19 additions & 9 deletions rest_framework/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.utils.translation import ugettext_lazy as _

from rest_framework.compat import (
crispy_forms, distinct, django_filters, guardian, template_render
coreapi, crispy_forms, distinct, django_filters, guardian, template_render
)
from rest_framework.settings import api_settings

Expand Down Expand Up @@ -72,7 +72,8 @@ def filter_queryset(self, request, queryset, view):
"""
raise NotImplementedError(".filter_queryset() must be overridden.")

def get_fields(self, view):
def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
return []


Expand Down Expand Up @@ -131,14 +132,21 @@ def to_html(self, request, queryset, view):
template = loader.get_template(self.template)
return template_render(template, context)

def get_fields(self, view):
def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
filter_class = getattr(view, 'filter_class', None)
if filter_class:
return list(filter_class().filters.keys())
return [
coreapi.Field(name=field_name, required=False, location='query')
for field_name in filter_class().filters.keys()
]

filter_fields = getattr(view, 'filter_fields', None)
if filter_fields:
return filter_fields
return [
coreapi.Field(name=field_name, required=False, location='query')
for field_name in filter_fields
]

return []

Expand Down Expand Up @@ -231,8 +239,9 @@ def to_html(self, request, queryset, view):
template = loader.get_template(self.template)
return template_render(template, context)

def get_fields(self, view):
return [self.search_param]
def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
return [coreapi.Field(name=self.search_param, required=False, location='query')]


class OrderingFilter(BaseFilterBackend):
Expand Down Expand Up @@ -347,8 +356,9 @@ def to_html(self, request, queryset, view):
context = self.get_template_context(request, queryset, view)
return template_render(template, context)

def get_fields(self, view):
return [self.ordering_param]
def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
return [coreapi.Field(name=self.ordering_param, required=False, location='query')]


class DjangoObjectPermissionsFilter(BaseFilterBackend):
Expand Down
34 changes: 24 additions & 10 deletions rest_framework/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from django.utils.six.moves.urllib import parse as urlparse
from django.utils.translation import ugettext_lazy as _

from rest_framework.compat import template_render
from rest_framework.compat import coreapi, template_render
from rest_framework.exceptions import NotFound
from rest_framework.response import Response
from rest_framework.settings import api_settings
Expand Down Expand Up @@ -157,7 +157,8 @@ def to_html(self): # pragma: no cover
def get_results(self, data):
return data['results']

def get_fields(self, view):
def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
return []


Expand Down Expand Up @@ -283,10 +284,16 @@ def to_html(self):
context = self.get_html_context()
return template_render(template, context)

def get_fields(self, view):
if self.page_size_query_param is None:
return [self.page_query_param]
return [self.page_query_param, self.page_size_query_param]
def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
fields = [
coreapi.Field(name=self.page_query_param, required=False, location='query')
]
if self.page_size_query_param is not None:
fields.append([
coreapi.Field(name=self.page_size_query_param, required=False, location='query')
])
return fields


class LimitOffsetPagination(BasePagination):
Expand Down Expand Up @@ -415,8 +422,12 @@ def to_html(self):
context = self.get_html_context()
return template_render(template, context)

def get_fields(self, view):
return [self.limit_query_param, self.offset_query_param]
def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
return [
coreapi.Field(name=self.limit_query_param, required=False, location='query'),
coreapi.Field(name=self.offset_query_param, required=False, location='query')
]


class CursorPagination(BasePagination):
Expand Down Expand Up @@ -721,5 +732,8 @@ def to_html(self):
context = self.get_html_context()
return template_render(template, context)

def get_fields(self, view):
return [self.cursor_query_param]
def get_schema_fields(self, view):
assert coreapi is not None, 'coreapi must be installed to use `get_schema_fields()`'
return [
coreapi.Field(name=self.cursor_query_param, required=False, location='query')
]
15 changes: 2 additions & 13 deletions rest_framework/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ def get_pk_name(model):
return _get_pk(meta).name


def as_query_fields(items):
"""
Take a list of Fields and plain strings.
Convert any pain strings into `location='query'` Field instances.
"""
return [
item if isinstance(item, coreapi.Field) else coreapi.Field(name=item, required=False, location='query')
for item in items
]


def is_api_view(callback):
"""
Return `True` if the given view callback is a REST framework view/viewset.
Expand Down Expand Up @@ -506,7 +495,7 @@ def get_pagination_fields(self, path, method, view):
return []

paginator = view.pagination_class()
return as_query_fields(paginator.get_fields(view))
return paginator.get_schema_fields(view)

def get_filter_fields(self, path, method, view):
if not is_list_view(path, method, view):
Expand All @@ -517,7 +506,7 @@ def get_filter_fields(self, path, method, view):

fields = []
for filter_backend in view.filter_backends:
fields += as_query_fields(filter_backend().get_fields(view))
fields += filter_backend().get_schema_fields(view)
return fields

# Method for generating the link layout....
Expand Down