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.
This is the first part of #6846.
Previously, the response schema for list views was an object representing a single item. However, list views return a list of items, and hence it should be an array.
Further work will need to be done to support how pagination classes modify list responses.
There should be no change for views not determined to be list views.
* add sans-serif fallback for Verdana in docs sidebar
Co-Authored-By: Joachim Jablon <ewjoachim@gmail.com>
* improve display for docs sidebar (#5638)
Co-Authored-By: Joachim Jablon <ewjoachim@gmail.com>
* Add tests for raise_errors_on_nested_writes
* Fix dotted-source field checking on serializer write
The code was previously checking the validated data for the field's
attribute name, however, the data contain the first source attr.
Refs #6509
This enforces allow_empty=True when a ListSerializer is a child of another serializer and partial validation is being performed on the parent serializer.
This is because partial validation should allow fields to be omitted, but should not cause values that are invalid without partial validation to become valid.
This effectively reverts #4222. None of the tests added in that PR fail if the associated change is removed, so I‘m not sure what that PR was trying to fix.
* fixes#6751
* reverted condition
* save instance before setting m2m fields
* added comment why m2m fields are saved after instance
* removed blank line
* added test for the issue 6751
It might be useful for a serializer with many many fields which uses
read_only and write_only on a large percentage of the fields. But the
memory usage and statefulness it adds are not worth it for the common
case.
* 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>
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().
Thanks to Jon Dufresne (@jdufresne) for review.
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Rizwan Mansuri <Rizwan@webbyfox.com>
* Introspect ManyRelatedField data type recursively
For all `ManyRelatedField` objects, we were assuming that the inner type was always a `String`. While this may be true for the default output, a `ManyRelatedField` is a wrapper for a lot of other classes which includes more than just strings. This should allow us to document lists of things other than strings.
* Added test for schemas for many-to-many fields
This adds a test that makes sure we generate the schema for a many-to-many field such that it actually has the right type. For some reason we did not previously have any tests for schema generation that included them, so hopefully this will prevent any future issues from popping up.
This should serve as a regression test for the `items` field on to-many relationships, which was previously forced to a `String` even though in most cases it is a different inner type within the array.
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.
* Use compat version of collections.abc.Mapping
Since the Mapping class will no longer be available to import directly
from the collections module in Python 3.8, we should use the
compatibility helper introduced in #6154 in the fields module.
* Alias and use compat version of collections.abc.MutableMapping
Since the MutableMapping class will no longer be available to import
directly from the collections module in Python 3.8, we should create an
alias for it in the compat module and use that instead.