Commit Graph

52 Commits

Author SHA1 Message Date
Max Muoto
7f18ec1b53
Revert "Ensure CursorPagination respects nulls in the ordering field (#8912)" (#9381)
This reverts commit b1cec517ff.
2024-04-27 17:07:05 +06:00
Sergey Klyuykov
7658ffd71d
Fix: Pagination response schemas. (#9049) 2023-07-15 15:26:56 +06:00
fdomain
f1a11d41cb
fix: fallback on CursorPagination ordering if unset on the view (#8954)
* this commit fixes the usage of a CursorPagination combined with a view
  implementing an ordering filter, without a default ordering value.
* former behavior was to fetch the ordering value from the filter, and
  raises an error if the value was None, preventing the fallback on the
  ordering set on the CursorPagination class itself.
* we reversed the logic by getting first the value set on the class,
  and override it by the ordering filter if the parameter is present
2023-05-02 06:55:59 +06:00
ddelange
b1cec517ff
Ensure CursorPagination respects nulls in the ordering field (#8912)
* Ensure CursorPagination respects nulls in the ordering field

* Lint

* Fix pagination tests

* Add test_ascending with nulls

* Push tests for nulls

* Test pass

* Add comment

* Fix test for django30
2023-04-08 16:42:28 +06:00
Shi Pengtao
0ae3323bd2
fix 404 when page query parameter is empty string (#8578)
* fix 404 when page query parameter is empty string

* Update pagination.py

* Update pagination.py

Co-authored-by: Tom Christie <tom@tomchristie.com>
2022-11-22 12:37:31 +06:00
Stanislav Levin
78cdae6999
Fix Pytest's deprecation warnings about nose usage (#8758)
Pytest 7.2.0 deprecated plain `setup` and `teardown` functions and
methods as nose idioms:
https://docs.pytest.org/en/latest/changelog.html#pytest-7-2-0-2022-10-23

`setup` can be safely replaced with `setup_method`:
https://docs.pytest.org/en/stable/deprecations.html#setup-teardown

Fixes: https://github.com/encode/django-rest-framework/issues/8757
Signed-off-by: Stanislav Levin <slev@altlinux.org>

Signed-off-by: Stanislav Levin <slev@altlinux.org>
2022-11-15 12:29:15 +00:00
Norbert Schuler
911b207fa1
Added examples to schema of CursorPagination (#8687)
* Added examples to schema of CursorPagination

Fix https://github.com/encode/django-rest-framework/issues/8686

Added missing examples for CursorPagination class to disable warnings in https://github.com/tfranzel/drf-spectacular and make it consistent with other pagination classes.

* Adapted test case for paginated response schema
2022-10-11 11:50:33 +01:00
Dhaval Mehta
e1336387d1
Added example for pagination in schemas. (#7275) 2020-04-24 16:13:13 +02:00
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
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
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
9d06e43d05 Replace type('') with six.text_type (#6482)
As all source files import unicode_literals, type('') is always
equivalent to six.text_type (str on Python 3 and unicode on Python 2).
Removes the need to call type(), is more explicit, and will be easier to
catch places to change for when it is time to eventually drop Python 2.
2019-03-05 12:11:46 +01:00
Kris Dorosz
60b9e58a12 Add support for page_size parameter in CursorPaginator class 2017-09-25 11:25:51 +02:00
Artem Muterko
d610d150f1 Add test for pagination when limit not set 2017-01-31 16:51:09 +02: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
Neil Parsons
7466b61e62 Don't strip empty query params when paginating (#4260) 2016-08-12 10:50:16 +01:00
Dmitry Dygalo
e1768bdc16 Fixed various typos (#4366) 2016-08-08 09:32:22 +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
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
Denis Cornehl
3806af3d15 allow setting a custom Django Paginator in pagination.PageNumberPagination 2015-11-13 16:04:12 +01:00
Tom Christie
7bfc420dc9 Add release notes, drop deprecated test 2015-10-22 15:11:10 +01:00
Tom Christie
22631c73a7 Resolve assertion error with LimitOffsetPagination and erronous parameters. Closes #2920. 2015-07-23 12:41:35 +01:00
José Padilla
7351a3f6ca Sort imports with isort 2015-06-25 16:55:51 -04:00
homm
9bc0319ff4 Revert tests 2015-06-23 19:02:05 +03:00
homm
b01e91eb71 test custom cursor format 2015-06-23 18:09:17 +03:00
homm
b3716ccb91 make MockObject, MockQuerySet and ExamplePagination visible outside of setup 2015-06-23 18:07:32 +03:00
Ash Hoover
35c28a2a71 Include correct limits in LimitOffsetPagination link urls 2015-06-05 08:56:33 -07:00
Tom Christie
18cc0230bf Clean up pagination attributes 2015-03-04 15:51:00 +00:00
Tom Christie
43d983fae8 Add paging controls 2015-01-22 17:25:12 +00:00
Tom Christie
0822c9e558 Cursor pagination now works with OrderingFilter 2015-01-22 16:12:05 +00:00
Tom Christie
408261ee02 Support ordering attribute either on view or on pagination class for CursorPagination 2015-01-22 15:15:52 +00:00
Tom Christie
83a82b44a5 Support for tuple ordering in cursor pagination 2015-01-22 15:07:01 +00:00
Tom Christie
94b5f7a86e Tidy up cursor tests and make more comprehensive 2015-01-22 12:14:52 +00:00
Tom Christie
f1af603fb0 Tests for reverse pagination 2015-01-22 10:51:04 +00:00
Tom Christie
cae9528c54 Add support for reverse cursors 2015-01-22 10:28:19 +00:00
Tom Christie
dbb684117f Add offset support for cursor pagination 2015-01-19 09:24:42 +00:00
Tom Christie
4919492582 First pass at cursor pagination 2015-01-17 00:10:43 +00:00
Tom Christie
86d2774cf3 Fix compat issues 2015-01-16 20:30:46 +00:00
Tom Christie
8b0f25aa0a More pagination tests & cleanup 2015-01-16 16:55:46 +00:00
Tom Christie
53edd37df5 Tests for LimitOffsetPagination 2015-01-15 21:07:05 +00:00
Tom Christie
73feaf6299 First pass at 3.1 pagination API 2015-01-09 15:30:36 +00:00
Tom Christie
79715f01f8 Coerce dates etc to ISO_8601 in seralizer, by default. 2014-09-12 12:10:22 +01:00
Tom Christie
040bfcc09c NotImplemented stubs for Field, and DecimalField improvements 2014-09-11 21:48:54 +01:00
Tom Christie
de301f3b66 Merge master 2014-09-11 13:20:44 +01:00
Michał Jaworski
deb19272b7 Add custom pagination test that covers case with custom object serializer class 2014-09-03 16:49:32 +02:00
Tom Christie
f2852811f9 Getting tests passing 2014-09-02 17:41:23 +01:00
Tom Christie
b3253b4283 Remove .model usage in tests.
Remove the shortcut `.model` view attribute usage from test cases.
2014-08-29 12:35:53 +01:00
Tom Christie
d2795dd26d Resolve linting issues 2014-08-19 13:54:52 +01:00
Tom Christie
bf09c32de8 Code linting and added runtests.py 2014-08-19 13:28:07 +01:00