Commit Graph

112 Commits

Author SHA1 Message Date
Reupen Shah
f8c16441fa Add support for pagination in OpenAPI response schemas (#6867)
Refs #6846

This provides a way for pagination classes to add pagination properties (`count`, `next`, `results` etc.) to OpenAPI response schemas.

A new method `get_paginated_response_schema()` has been added to `BasePagination`. This method is intended to mirror `get_paginated_response()` (which takes a `list` and wraps it in a `dict`). 

Hence, `get_paginated_response_schema()` takes an unpaginated response schema (of type `array`) and wraps that with a schema object of type `object` containing the relevant properties that the pagination class adds to responses.

The default implementation of `BasePagination.get_paginated_response_schema()` simply passes the schema through unmodified, for backwards compatibility.
2019-09-03 15:25:44 +02:00
Gregory N. Schmit
335054a5d3 replace force_text with force_str 2019-08-07 21:05:24 +02:00
Joachim Jablon
43a9cc1b7a Fix CursorPagination when objects get deleted between calls (#6504) (#6593)
* Added regression tests (#6504)

Co-Authored-By: Tom Quinonero <tq@3yourmind.com>

* Fix CursorPagination when objects get deleted between calls (#6504)

Co-Authored-By: Tom Quinonero <tq@3yourmind.com>
2019-05-20 14:41:31 +01:00
Carlton Gibson
37f210a455
Added OpenAPI Schema Generation. (#6532)
Co-authored-by: Lucidiot <lucidiot@protonmail.com>
Co-authored-by: dongfangtianyu <dongfangtianyu@qq.com>
2019-05-13 16:07:03 +02:00
Jon Dufresne
3f19e66d9f Replace all usage ugettext functions with the non-u versions (#6634)
On Python 3, the ugettext functions are a simple aliases of their non-u
counterparts (the 'u' represents Python 2 unicode type). Starting with
Django 3.0, the u versions will be deprecated.

https://docs.djangoproject.com/en/dev/releases/3.0/#id2

> django.utils.translation.ugettext(), ugettext_lazy(), ugettext_noop(),
> ungettext(), and ungettext_lazy() are deprecated in favor of the
> functions that they’re aliases for:
> django.utils.translation.gettext(), gettext_lazy(), gettext_noop(),
> ngettext(), and ngettext_lazy().
2019-05-01 07:49:54 +02:00
Carlton Gibson
0407a0df8a
Dropped Python 2 compatibility. (#6615)
Thanks to Jon Dufresne (@jdufresne) for review.

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Rizwan Mansuri <Rizwan@webbyfox.com>
2019-04-30 17:53:44 +02:00
Jon Dufresne
878f9d2783 Prefer https:// for URLs when available throughout project (#6208) 2018-10-02 08:28:58 +02:00
oliver
bcc565f387 Clean up unnecessary if statement (#6163) 2018-09-06 07:25:20 +01:00
Charlie McBride
a7e2a7bfcd Add LimitOffsetPagination.get_count to allow method override (#5846)
* Add LimitOffsetPagination.get_count to allow method override

* Format method docstring
2018-03-23 22:25:43 +00:00
Daniel Hahler
2854679f56 Upgrade isort (#5817)
* Fix isort

* runtests: add --diff to ISORT_ARGS

* requirements-codestyle: bump isort to 4.3.3

* isort: move config to setup.cfg
2018-02-14 20:12:14 +00:00
Carlton Gibson
c674687782 Remove Django 1.8 & 1.9 compatibility code (#5481)
* Identify code that needs to be pulled out of/removed from compat.py

* Extract modern code from get_names_and_managers in compat.py and remove compat code

* Extract modern code from is_authenticated() in compat.py and remove.

* Extract modern code from is_anonymous() in compat.py and remove

* Extract modern code from get_related_model() from compat.py and remove

* Extract modern code from value_from_object() in compat.py and remove

* Update postgres compat

JSONField now always available.

* Remove DecimalValidator compat

* Remove get_remote_field compat

* Remove template_render compat

Plus isort.

* Remove set_many compat

* Remove include compat
2017-10-05 20:41:38 +02:00
Kris Dorosz
60b9e58a12 Add support for page_size parameter in CursorPaginator class 2017-09-25 11:25:51 +02:00
Yury V. Zaytsev
96d6a9a6da Docs: update link in pagination.py (#5321)
The blog post referenced in the documentation has been since moved to a new location.
2017-08-09 15:19:43 -04:00
Erick Delfin
089887d56e Simplified chained comparisons and minor code fixes (#5276) 2017-07-16 17:12:29 +01:00
Tom Christie
60dbe72a62 Merge pull request #4437 from dfavato/master
Set self.count before self.limit in LimitOffsetPagination
2017-05-02 10:21:36 +01:00
Tom Christie
68d2020112 Live API documentation (#4755) 2017-03-03 15:24:37 +00:00
Artem Muterko
4dd71d68d2 Remove extra parentheses (#4789) 2017-01-08 16:09:23 +00:00
Kennedy Mwenja
7038571157 Enable cursor pagination of value querysets. (#4569)
To do `GROUP_BY` queries in django requires one to use `.values()`
eg this groups posts by user getting a count of posts per user.

```
Posts.objects.order_by('user').values('user').annotate(post_count=Count('post'))
```

This would produce a value queryset which serializes its result
objects as dictionaries while `CursorPagination` requires a queryset
with result objects that are model instances.

This commit enables cursor pagination for value querysets.

- had to mangle the tests a bit to test it out. They might need
  some refactoring.
- tried the same for `.values_list()` but it turned out to be
  trickier than I expected since you have to use tuple indexes.
2016-11-01 10:42:01 +00:00
Alexey Evseev
2519ce9128 Fix schema generation with custom page_size pagination param (#4567) 2016-10-12 16:09:45 +01:00
Tom Christie
0dec36eb41 Version 3.5 (#4525)
* Start test case

* Added 'requests' test client

* Address typos

* Graceful fallback if requests is not installed.

* Add cookie support

* Tests for auth and CSRF

* Py3 compat

* py3 compat

* py3 compat

* Add get_requests_client

* Added SchemaGenerator.should_include_link

* add settings for html cutoff on related fields

* Router doesn't work if prefix is blank, though project urls.py handles prefix

* Fix Django 1.10 to-many deprecation

* Add django.core.urlresolvers compatibility

* Update django-filter & django-guardian

* Check for empty router prefix; adjust URL accordingly

It's easiest to fix this issue after we have made the regex.  To try
to fix it before would require doing something different for List vs
Detail, which means we'd have to know which type of url we're
constructing before acting accordingly.

* Fix misc django deprecations

* Use TOC extension instead of header

* Fix deprecations for py3k

* Add py3k compatibility to is_simple_callable

* Add is_simple_callable tests

* Drop python 3.2 support (EOL, Dropped by Django)

* schema_renderers= should *set* the renderers, not append to them.

* API client (#4424)

* Fix release notes

* Add note about 'User account is disabled.' vs 'Unable to log in'

* Clean up schema generation (#4527)

* Handle multiple methods on custom action (#4529)

* RequestsClient, CoreAPIClient

* exclude_from_schema

* Added 'get_schema_view()' shortcut

* Added schema descriptions

* Better descriptions for schemas

* Add type annotation to schema generation

* Coerce schema 'pk' in path to actual field name

* Deprecations move into assertion errors

* Use get_schema_view in tests

* Updte CoreJSON media type

* Handle schema structure correctly when path prefixs exist. Closes #4401

* Add PendingDeprecation to Router schema generation.

* Added SCHEMA_COERCE_PATH_PK and SCHEMA_COERCE_METHOD_NAMES

* Renamed and documented 'get_schema_fields' interface.
2016-10-10 13:03:46 +01:00
dfavato
ec4761225e Set self.count before self.limit in LimitOffsetPagination
By doing this it is possible to override get_limit in order to return all records if the request has a predefined param.

For example, if one wants that all records are retrieved if url has &limit=-1, get_limit could return self.count in this case.

Otherwise, if self.count is set after self.limit then, to achive the same result, one has to override get_limit and paginate_queryset, or run get_limit twice.
2016-08-23 14:52:20 -03:00
Tom Christie
ebf43346a1 Do not re-run query for empty results with LimitOffsetPagination (#4388) 2016-08-11 16:54:55 +01:00
Dmitry Dygalo
e1768bdc16 Fixed various typos (#4366) 2016-08-08 09:32:22 +01:00
Tom Christie
6ff9840bde Schemas & client libraries. (#4179)
* Added schema generation support.
* New tutorial section.
* API guide on schema generation.
* Topic guide on API clients.
2016-07-04 16:38:17 +01:00
Rowan Seymour
36ca4b8e06 Make offset_cutoff a class attribute in CursorPagination so that it can be easily overridden in subclasses (#4212) 2016-06-23 10:37:15 +01:00
Tom Christie
2e7fae7698 limit=0 should revert to default limit (#4194) 2016-06-13 16:32:43 +01:00
José Padilla
0795f7394c Prevent raising exception when limit is 0 (#4098) 2016-05-10 10:58:24 +01:00
Xavier Ordoquy
bff3bebdbe Merge remote-tracking branch 'reference/stable/3.3.x' into merge_test
# Conflicts:
#	docs/topics/release-notes.md
2016-04-08 15:46:17 +02:00
Tom Viner
3e5a1397d7 remove trailing slash from cramer cursor link 2016-03-24 20:37:38 +00:00
Xavier Ordoquy
5e08231453 Remove informations about why the pagination didn't work.
We remove a couple of informations to lower the exposition of our internals.
2016-02-17 18:18:19 +01:00
Tom Christie
832d6322a7 Merge pull request #3631 from syphar/paginat
allow setting a custom Django Paginator class
2015-11-30 20:58:32 +00:00
Andrei Fokau
802ee5d0ea Fix template.render deprecation warnings for 1.9+ 2015-11-18 17:06:35 +01:00
Denis Cornehl
3806af3d15 allow setting a custom Django Paginator in pagination.PageNumberPagination 2015-11-13 16:04:12 +01:00
Tom Christie
0fb1ebcfcf Remove unused import 2015-10-23 16:07:48 +01:00
Tom Christie
cf33008571 Release notes etc 2015-10-22 14:05:52 +01:00
Omer Katz
2e178bc970 Replaced all dict and set conversions from lists to dict and set literals. 2015-10-17 12:00:11 +03:00
Carlton Gibson
45ace5010e Remove OrderedDict fallback 2015-09-22 16:35:38 +02:00
Tom Christie
aa4cd7e9d7 Guard against LimitOffsetPagination edge case. Closes #3303. 2015-08-20 10:12:52 +01:00
Tom Christie
7b51508600 Error on double underscore ordering with CursorPagination. Refs #3221. 2015-08-05 13:42:44 +01:00
Tom Christie
c203ca4c64 Deprecations 2015-07-30 15:26:42 +01:00
Tom Christie
b996266431 Merge master 2015-07-23 15:28:29 +01:00
Tom Christie
22631c73a7 Resolve assertion error with LimitOffsetPagination and erronous parameters. Closes #2920. 2015-07-23 12:41:35 +01:00
Tom Christie
c879aaf398 page_size needs to be stored as state on CursorPagination. Refs 3147. 2015-07-16 10:26:16 +01:00
Tom Christie
468361425d page_size should be local, not overwriting class attribute. 2015-07-14 12:32:27 +01:00
Tom Christie
2b51d5594b Remove whitespace and comment changes 2015-07-14 11:41:25 +01:00
Tom Christie
14a32ae32d Add get_page_size hook to CursorPagination. Closes #3068. 2015-07-14 11:40:15 +01:00
Tom Christie
1d012aeb93 Merge branch 'cursor-limits' of https://github.com/uploadcare/django-rest-framework into uploadcare-cursor-limits 2015-07-14 11:37:18 +01:00
homm
a3afcfb6d3 duplicate get_page_size and related properties from PageNumberPagination 2015-07-13 14:44:48 +03:00
homm
59905e9335 revert BasePageSizePagination class and CursorPagination inheritance 2015-07-13 14:36:47 +03:00
José Padilla
7351a3f6ca Sort imports with isort 2015-06-25 16:55:51 -04:00