Skip to content

Commit a74445d

Browse files
authored
Merge branch 'encode:master' into 315_rn
2 parents 6c15585 + 4f7e9ed commit a74445d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2054
-413
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
steps:
2525
- uses: actions/checkout@v3
2626

27-
- uses: actions/setup-python@v3
27+
- uses: actions/setup-python@v4
2828
with:
2929
python-version: ${{ matrix.python-version }}
3030
cache: 'pip'
@@ -34,18 +34,24 @@ jobs:
3434
run: python -m pip install --upgrade pip setuptools virtualenv wheel
3535

3636
- name: Install dependencies
37-
run: python -m pip install --upgrade codecov tox tox-py
37+
run: python -m pip install --upgrade codecov tox
38+
39+
- name: Install tox-py
40+
if: ${{ matrix.python-version == '3.6' }}
41+
run: python -m pip install --upgrade tox-py
42+
43+
- name: Run tox targets for ${{ matrix.python-version }}
44+
if: ${{ matrix.python-version != '3.6' }}
45+
run: tox run -f py$(echo ${{ matrix.python-version }} | tr -d .)
3846

3947
- name: Run tox targets for ${{ matrix.python-version }}
48+
if: ${{ matrix.python-version == '3.6' }}
4049
run: tox --py current
4150

4251
- name: Run extra tox targets
4352
if: ${{ matrix.python-version == '3.9' }}
4453
run: |
45-
python setup.py bdist_wheel
46-
rm -r djangorestframework.egg-info # see #6139
4754
tox -e base,dist,docs
48-
tox -e dist --installpkg ./dist/djangorestframework-*.whl
4955
5056
- name: Upload coverage
5157
run: |

.github/workflows/pre-commit.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ on:
88

99
jobs:
1010
pre-commit:
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
1515
with:
1616
fetch-depth: 0
1717

18-
- uses: actions/setup-python@v2
18+
- uses: actions/setup-python@v4
1919
with:
20-
python-version: 3.9
20+
python-version: "3.10"
2121

22-
- uses: pre-commit/action@v2.0.0
22+
- uses: pre-commit/action@v3.0.0
2323
with:
2424
token: ${{ secrets.GITHUB_TOKEN }}

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
- id: check-symlinks
1010
- id: check-toml
1111
- repo: https://github.com/pycqa/isort
12-
rev: 5.8.0
12+
rev: 5.12.0
1313
hooks:
1414
- id: isort
1515
- repo: https://github.com/PyCQA/flake8

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ There is a live example API for testing purposes, [available here][sandbox].
5555
# Requirements
5656

5757
* Python 3.6+
58-
* Django 4.1, 4.0, 3.2, 3.1, 3.0
58+
* Django 4.2, 4.1, 4.0, 3.2, 3.1, 3.0
5959

6060
We **highly recommend** and only officially support the latest patch release of
6161
each Python and Django series.

docs/api-guide/authentication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ The [HawkREST][hawkrest] library builds on the [Mohawk][mohawk] library to let y
414414

415415
## HTTP Signature Authentication
416416

417-
HTTP Signature (currently a [IETF draft][http-signature-ietf-draft]) provides a way to achieve origin authentication and message integrity for HTTP messages. Similar to [Amazon's HTTP Signature scheme][amazon-http-signature], used by many of its services, it permits stateless, per-request authentication. [Elvio Toccalino][etoccalino] maintains the [djangorestframework-httpsignature][djangorestframework-httpsignature] (outdated) package which provides an easy to use HTTP Signature Authentication mechanism. You can use the updated fork version of [djangorestframework-httpsignature][djangorestframework-httpsignature], which is [drf-httpsig][drf-httpsig].
417+
HTTP Signature (currently a [IETF draft][http-signature-ietf-draft]) provides a way to achieve origin authentication and message integrity for HTTP messages. Similar to [Amazon's HTTP Signature scheme][amazon-http-signature], used by many of its services, it permits stateless, per-request authentication. [Elvio Toccalino][etoccalino] maintains the [djangorestframework-httpsignature][djangorestframework-httpsignature] (outdated) package which provides an easy-to-use HTTP Signature Authentication mechanism. You can use the updated fork version of [djangorestframework-httpsignature][djangorestframework-httpsignature], which is [drf-httpsig][drf-httpsig].
418418

419419
## Djoser
420420

docs/api-guide/exceptions.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ By default this exception results in a response with the HTTP status code "403 F
179179

180180
**Signature:** `NotFound(detail=None, code=None)`
181181

182-
Raised when a resource does not exists at the given URL. This exception is equivalent to the standard `Http404` Django exception.
182+
Raised when a resource does not exist at the given URL. This exception is equivalent to the standard `Http404` Django exception.
183183

184184
By default this exception results in a response with the HTTP status code "404 Not Found".
185185

@@ -217,11 +217,10 @@ By default this exception results in a response with the HTTP status code "429 T
217217

218218
## ValidationError
219219

220-
**Signature:** `ValidationError(detail, code=None)`
220+
**Signature:** `ValidationError(detail=None, code=None)`
221221

222222
The `ValidationError` exception is slightly different from the other `APIException` classes:
223223

224-
* The `detail` argument is mandatory, not optional.
225224
* The `detail` argument may be a list or dictionary of error details, and may also be a nested data structure. By using a dictionary, you can specify field-level errors while performing object-level validation in the `validate()` method of a serializer. For example. `raise serializers.ValidationError({'name': 'Please enter a valid name.'})`
226225
* By convention you should import the serializers module and use a fully qualified `ValidationError` style, in order to differentiate it from Django's built-in validation error. For example. `raise serializers.ValidationError('This field must be an integer value.')`
227226

docs/api-guide/fields.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Corresponds to `django.forms.fields.IPAddressField` and `django.forms.fields.Gen
251251

252252
**Signature**: `IPAddressField(protocol='both', unpack_ipv4=False, **options)`
253253

254-
* `protocol` Limits valid inputs to the specified protocol. Accepted values are 'both' (default), 'IPv4' or 'IPv6'. Matching is case insensitive.
254+
* `protocol` Limits valid inputs to the specified protocol. Accepted values are 'both' (default), 'IPv4' or 'IPv6'. Matching is case-insensitive.
255255
* `unpack_ipv4` Unpacks IPv4 mapped addresses like ::ffff:192.0.2.1. If this option is enabled that address would be unpacked to 192.0.2.1. Default is disabled. Can only be used when protocol is set to 'both'.
256256

257257
---
@@ -294,7 +294,7 @@ Corresponds to `django.db.models.fields.DecimalField`.
294294
* `max_value` Validate that the number provided is no greater than this value.
295295
* `min_value` Validate that the number provided is no less than this value.
296296
* `localize` Set to `True` to enable localization of input and output based on the current locale. This will also force `coerce_to_string` to `True`. Defaults to `False`. Note that data formatting is enabled if you have set `USE_L10N=True` in your settings file.
297-
* `rounding` Sets the rounding mode used when quantising to the configured precision. Valid values are [`decimal` module rounding modes][python-decimal-rounding-modes]. Defaults to `None`.
297+
* `rounding` Sets the rounding mode used when quantizing to the configured precision. Valid values are [`decimal` module rounding modes][python-decimal-rounding-modes]. Defaults to `None`.
298298
* `normalize_output` Will normalize the decimal value when serialized. This will strip all trailing zeroes and change the value's precision to the minimum required precision to be able to represent the value without loosing data. Defaults to `False`.
299299

300300
#### Example usage
@@ -321,13 +321,13 @@ Corresponds to `django.db.models.fields.DateTimeField`.
321321

322322
* `format` - A string representing the output format. If not specified, this defaults to the same value as the `DATETIME_FORMAT` settings key, which will be `'iso-8601'` unless set. Setting to a format string indicates that `to_representation` return values should be coerced to string output. Format strings are described below. Setting this value to `None` indicates that Python `datetime` objects should be returned by `to_representation`. In this case the datetime encoding will be determined by the renderer.
323323
* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `DATETIME_INPUT_FORMATS` setting will be used, which defaults to `['iso-8601']`.
324-
* `default_timezone` - A `tzinfo` subclass (`zoneinfo` or `pytz`) prepresenting the timezone. If not specified and the `USE_TZ` setting is enabled, this defaults to the [current timezone][django-current-timezone]. If `USE_TZ` is disabled, then datetime objects will be naive.
324+
* `default_timezone` - A `tzinfo` subclass (`zoneinfo` or `pytz`) representing the timezone. If not specified and the `USE_TZ` setting is enabled, this defaults to the [current timezone][django-current-timezone]. If `USE_TZ` is disabled, then datetime objects will be naive.
325325

326326
#### `DateTimeField` format strings.
327327

328328
Format strings may either be [Python strftime formats][strftime] which explicitly specify the format, or the special string `'iso-8601'`, which indicates that [ISO 8601][iso8601] style datetimes should be used. (eg `'2013-01-29T12:34:56.000000Z'`)
329329

330-
When a value of `None` is used for the format `datetime` objects will be returned by `to_representation` and the final output representation will determined by the renderer class.
330+
When a value of `None` is used for the format `datetime` objects will be returned by `to_representation` and the final output representation will be determined by the renderer class.
331331

332332
#### `auto_now` and `auto_now_add` model fields.
333333

docs/api-guide/filtering.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ The `OrderingFilter` class supports simple query parameter controlled ordering o
253253

254254
![Ordering Filter](../img/ordering-filter.png)
255255

256-
By default, the query parameter is named `'ordering'`, but this may by overridden with the `ORDERING_PARAM` setting.
256+
By default, the query parameter is named `'ordering'`, but this may be overridden with the `ORDERING_PARAM` setting.
257257

258258
For example, to order users by username:
259259

@@ -269,7 +269,7 @@ Multiple orderings may also be specified:
269269

270270
### Specifying which fields may be ordered against
271271

272-
It's recommended that you explicitly specify which fields the API should allowing in the ordering filter. You can do this by setting an `ordering_fields` attribute on the view, like so:
272+
It's recommended that you explicitly specify which fields the API should allow in the ordering filter. You can do this by setting an `ordering_fields` attribute on the view, like so:
273273

274274
class UserListView(generics.ListAPIView):
275275
queryset = User.objects.all()

docs/api-guide/pagination.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ Suppose we want to replace the default pagination output style with a modified f
240240
'results': data
241241
})
242242

243-
We'd then need to setup the custom class in our configuration:
243+
We'd then need to set up the custom class in our configuration:
244244

245245
REST_FRAMEWORK = {
246246
'DEFAULT_PAGINATION_CLASS': 'my_project.apps.core.pagination.CustomPagination',
@@ -262,7 +262,7 @@ API responses for list endpoints will now include a `Link` header, instead of in
262262

263263
![Link Header][link-header]
264264

265-
*A custom pagination style, using the 'Link' header'*
265+
*A custom pagination style, using the 'Link' header*
266266

267267
---
268268

docs/api-guide/parsers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ sending more complex data than simple forms
1111
>
1212
> — Malcom Tredinnick, [Django developers group][cite]
1313
14-
REST framework includes a number of built in Parser classes, that allow you to accept requests with various media types. There is also support for defining your own custom parsers, which gives you the flexibility to design the media types that your API accepts.
14+
REST framework includes a number of built-in Parser classes, that allow you to accept requests with various media types. There is also support for defining your own custom parsers, which gives you the flexibility to design the media types that your API accepts.
1515

1616
## How the parser is determined
1717

docs/api-guide/permissions.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,20 @@ This permission is suitable if you want your API to only be accessible to a subs
165165

166166
## IsAuthenticatedOrReadOnly
167167

168-
The `IsAuthenticatedOrReadOnly` will allow authenticated users to perform any request. Requests for unauthorised users will only be permitted if the request method is one of the "safe" methods; `GET`, `HEAD` or `OPTIONS`.
168+
The `IsAuthenticatedOrReadOnly` will allow authenticated users to perform any request. Requests for unauthenticated users will only be permitted if the request method is one of the "safe" methods; `GET`, `HEAD` or `OPTIONS`.
169169

170170
This permission is suitable if you want to your API to allow read permissions to anonymous users, and only allow write permissions to authenticated users.
171171

172172
## DjangoModelPermissions
173173

174174
This permission class ties into Django's standard `django.contrib.auth` [model permissions][contribauth]. This permission must only be applied to views that have a `.queryset` property or `get_queryset()` method. Authorization will only be granted if the user *is authenticated* and has the *relevant model permissions* assigned. The appropriate model is determined by checking `get_queryset().model` or `queryset.model`.
175175

176+
* `GET` requests require the user to have the `view` or `change` permission on the model
176177
* `POST` requests require the user to have the `add` permission on the model.
177178
* `PUT` and `PATCH` requests require the user to have the `change` permission on the model.
178179
* `DELETE` requests require the user to have the `delete` permission on the model.
179180

180-
The default behavior can also be overridden to support custom model permissions. For example, you might want to include a `view` model permission for `GET` requests.
181+
The default behaviour can also be overridden to support custom model permissions.
181182

182183
To use custom model permissions, override `DjangoModelPermissions` and set the `.perms_map` property. Refer to the source code for details.
183184

@@ -201,7 +202,7 @@ As with `DjangoModelPermissions` you can use custom model permissions by overrid
201202

202203
---
203204

204-
**Note**: If you need object level `view` permissions for `GET`, `HEAD` and `OPTIONS` requests and are using django-guardian for your object-level permissions backend, you'll want to consider using the `DjangoObjectPermissionsFilter` class provided by the [`djangorestframework-guardian` package][django-rest-framework-guardian]. It ensures that list endpoints only return results including objects for which the user has appropriate view permissions.
205+
**Note**: If you need object level `view` permissions for `GET`, `HEAD` and `OPTIONS` requests and are using django-guardian for your object-level permissions backend, you'll want to consider using the `DjangoObjectPermissionsFilter` class provided by the [`djangorestframework-guardian2` package][django-rest-framework-guardian2]. It ensures that list endpoints only return results including objects for which the user has appropriate view permissions.
205206

206207
---
207208

@@ -356,6 +357,6 @@ The [Django Rest Framework PSQ][drf-psq] package is an extension that gives supp
356357
[rest-framework-roles]: https://github.com/Pithikos/rest-framework-roles
357358
[djangorestframework-api-key]: https://florimondmanca.github.io/djangorestframework-api-key/
358359
[django-rest-framework-role-filters]: https://github.com/allisson/django-rest-framework-role-filters
359-
[django-rest-framework-guardian]: https://github.com/rpkilby/django-rest-framework-guardian
360+
[django-rest-framework-guardian2]: https://github.com/johnthagen/django-rest-framework-guardian2
360361
[drf-access-policy]: https://github.com/rsinger86/drf-access-policy
361362
[drf-psq]: https://github.com/drf-psq/drf-psq

docs/api-guide/reverse.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ As with the `reverse` function, you should **include the request as a keyword ar
5454
api_root = reverse_lazy('api-root', request=request)
5555

5656
[cite]: https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_1_5
57-
[reverse]: https://docs.djangoproject.com/en/stable/topics/http/urls/#reverse
58-
[reverse-lazy]: https://docs.djangoproject.com/en/stable/topics/http/urls/#reverse-lazy
57+
[reverse]: https://docs.djangoproject.com/en/stable/ref/urlresolvers/#reverse
58+
[reverse-lazy]: https://docs.djangoproject.com/en/stable/ref/urlresolvers/#reverse-lazy

docs/api-guide/routers.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,23 @@ This behavior can be modified by setting the `trailing_slash` argument to `False
167167

168168
Trailing slashes are conventional in Django, but are not used by default in some other frameworks such as Rails. Which style you choose to use is largely a matter of preference, although some javascript frameworks may expect a particular routing style.
169169

170-
The router will match lookup values containing any characters except slashes and period characters. For a more restrictive (or lenient) lookup pattern, set the `lookup_value_regex` attribute on the viewset. For example, you can limit the lookup to valid UUIDs:
170+
By default the URLs created by `SimpleRouter` use regular expressions. This behavior can be modified by setting the `use_regex_path` argument to `False` when instantiating the router, in this case [path converters][path-converters-topic-reference] are used. For example:
171+
172+
router = SimpleRouter(use_regex_path=False)
173+
174+
**Note**: `use_regex_path=False` only works with Django 2.x or above, since this feature was introduced in 2.0.0. See [release note][simplified-routing-release-note]
175+
176+
177+
The router will match lookup values containing any characters except slashes and period characters. For a more restrictive (or lenient) lookup pattern, set the `lookup_value_regex` attribute on the viewset or `lookup_value_converter` if using path converters. For example, you can limit the lookup to valid UUIDs:
171178

172179
class MyModelViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSet):
173180
lookup_field = 'my_model_id'
174181
lookup_value_regex = '[0-9a-f]{32}'
175182

183+
class MyPathModelViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSet):
184+
lookup_field = 'my_model_uuid'
185+
lookup_value_converter = 'uuid'
186+
176187
## DefaultRouter
177188

178189
This router is similar to `SimpleRouter` as above, but additionally includes a default API root view, that returns a response containing hyperlinks to all the list views. It also generates routes for optional `.json` style format suffixes.
@@ -340,3 +351,5 @@ The [`DRF-extensions` package][drf-extensions] provides [routers][drf-extensions
340351
[drf-extensions-customizable-endpoint-names]: https://chibisov.github.io/drf-extensions/docs/#controller-endpoint-name
341352
[url-namespace-docs]: https://docs.djangoproject.com/en/4.0/topics/http/urls/#url-namespaces
342353
[include-api-reference]: https://docs.djangoproject.com/en/4.0/ref/urls/#include
354+
[simplified-routing-release-note]: https://docs.djangoproject.com/en/2.0/releases/2.0/#simplified-url-routing-syntax
355+
[path-converters-topic-reference]: https://docs.djangoproject.com/en/2.0/topics/http/urls/#path-converters

docs/api-guide/serializers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ Individual fields on a serializer can include validators, by declaring them on t
226226
raise serializers.ValidationError('Not a multiple of ten')
227227

228228
class GameRecord(serializers.Serializer):
229-
score = IntegerField(validators=[multiple_of_ten])
229+
score = serializers.IntegerField(validators=[multiple_of_ten])
230230
...
231231

232232
Serializer classes can also include reusable validators that are applied to the complete set of field data. These validators are included by declaring them on an inner `Meta` class, like so:
@@ -758,11 +758,11 @@ This is `True` by default, but can be set to `False` if you want to disallow emp
758758

759759
### `max_length`
760760

761-
This is `None` by default, but can be set to a positive integer if you want to validates that the list contains no more than this number of elements.
761+
This is `None` by default, but can be set to a positive integer if you want to validate that the list contains no more than this number of elements.
762762

763763
### `min_length`
764764

765-
This is `None` by default, but can be set to a positive integer if you want to validates that the list contains no fewer than this number of elements.
765+
This is `None` by default, but can be set to a positive integer if you want to validate that the list contains no fewer than this number of elements.
766766

767767
### Customizing `ListSerializer` behavior
768768

0 commit comments

Comments
 (0)