Skip to content

Commit 277e04a

Browse files
authored
Merge branch 'encode:master' into jsonencoder_ipaddress
2 parents d403188 + f56b85b commit 277e04a

30 files changed

+137
-91
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- '3.11'
2323

2424
steps:
25-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@v4
2626

2727
- uses: actions/setup-python@v4
2828
with:

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ repos:
1818
- id: flake8
1919
additional_dependencies:
2020
- flake8-tidy-imports
21+
- repo: https://github.com/adamchainz/blacken-docs
22+
rev: 1.13.0
23+
hooks:
24+
- id: blacken-docs
25+
exclude: ^(?!docs).*$
26+
additional_dependencies:
27+
- black==23.1.0

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contributing to REST framework
22

3-
At this point in it's lifespan we consider Django REST framework to be essentially feature-complete. We may accept pull requests that track the continued development of Django versions, but would prefer not to accept new features or code formatting changes.
3+
At this point in its lifespan we consider Django REST framework to be essentially feature-complete. We may accept pull requests that track the continued development of Django versions, but would prefer not to accept new features or code formatting changes.
44

55
Apart from minor documentation changes, the [GitHub discussions page](https://github.com/encode/django-rest-framework/discussions) should generally be your starting point. Please only raise an issue or pull request if you've been recommended to do so after discussion.
66

docs/api-guide/authentication.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ More information can be found in the [Documentation](https://django-rest-durin.r
454454
[basicauth]: https://tools.ietf.org/html/rfc2617
455455
[permission]: permissions.md
456456
[throttling]: throttling.md
457-
[csrf-ajax]: https://docs.djangoproject.com/en/stable/ref/csrf/#ajax
457+
[csrf-ajax]: https://docs.djangoproject.com/en/stable/howto/csrf/#using-csrf-protection-with-ajax
458458
[mod_wsgi_official]: https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIPassAuthorization.html
459459
[django-oauth-toolkit-getting-started]: https://django-oauth-toolkit.readthedocs.io/en/latest/rest-framework/getting_started.html
460460
[django-rest-framework-oauth]: https://jpadilla.github.io/django-rest-framework-oauth/

docs/api-guide/caching.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,33 @@ from rest_framework import viewsets
2828

2929
class UserViewSet(viewsets.ViewSet):
3030
# With cookie: cache requested url for each user for 2 hours
31-
@method_decorator(cache_page(60*60*2))
31+
@method_decorator(cache_page(60 * 60 * 2))
3232
@method_decorator(vary_on_cookie)
3333
def list(self, request, format=None):
3434
content = {
35-
'user_feed': request.user.get_user_feed()
35+
"user_feed": request.user.get_user_feed(),
3636
}
3737
return Response(content)
3838

3939

4040
class ProfileView(APIView):
4141
# With auth: cache requested url for each user for 2 hours
42-
@method_decorator(cache_page(60*60*2))
43-
@method_decorator(vary_on_headers("Authorization",))
42+
@method_decorator(cache_page(60 * 60 * 2))
43+
@method_decorator(vary_on_headers("Authorization"))
4444
def get(self, request, format=None):
4545
content = {
46-
'user_feed': request.user.get_user_feed()
46+
"user_feed": request.user.get_user_feed(),
4747
}
4848
return Response(content)
4949

5050

5151
class PostView(APIView):
5252
# Cache page for the requested url
53-
@method_decorator(cache_page(60*60*2))
53+
@method_decorator(cache_page(60 * 60 * 2))
5454
def get(self, request, format=None):
5555
content = {
56-
'title': 'Post title',
57-
'body': 'Post content'
56+
"title": "Post title",
57+
"body": "Post content",
5858
}
5959
return Response(content)
6060
```

docs/api-guide/schemas.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ urlpatterns = [
9494
# Use the `get_schema_view()` helper to add a `SchemaView` to project URLs.
9595
# * `title` and `description` parameters are passed to `SchemaGenerator`.
9696
# * Provide view name for use with `reverse()`.
97-
path('openapi', get_schema_view(
98-
title="Your Project",
99-
description="API for all things …",
100-
version="1.0.0"
101-
), name='openapi-schema'),
97+
path(
98+
"openapi",
99+
get_schema_view(
100+
title="Your Project", description="API for all things …", version="1.0.0"
101+
),
102+
name="openapi-schema",
103+
),
102104
# ...
103105
]
104106
```
@@ -259,11 +261,13 @@ class CustomSchema(AutoSchema):
259261
"""
260262
AutoSchema subclass using schema_extra_info on the view.
261263
"""
264+
262265
...
263266

267+
264268
class CustomView(APIView):
265269
schema = CustomSchema()
266-
schema_extra_info = ... some extra info ...
270+
schema_extra_info = ... # some extra info
267271
```
268272

269273
Here, the `AutoSchema` subclass goes looking for `schema_extra_info` on the
@@ -278,10 +282,13 @@ class BaseSchema(AutoSchema):
278282
"""
279283
AutoSchema subclass that knows how to use extra_info.
280284
"""
285+
281286
...
282287

288+
283289
class CustomSchema(BaseSchema):
284-
extra_info = ... some extra info ...
290+
extra_info = ... # some extra info
291+
285292

286293
class CustomView(APIView):
287294
schema = CustomSchema()
@@ -302,10 +309,9 @@ class CustomSchema(BaseSchema):
302309
self.extra_info = kwargs.pop("extra_info")
303310
super().__init__(**kwargs)
304311

312+
305313
class CustomView(APIView):
306-
schema = CustomSchema(
307-
extra_info=... some extra info ...
308-
)
314+
schema = CustomSchema(extra_info=...) # some extra info
309315
```
310316

311317
This saves you having to create a custom subclass per-view for a commonly used option.

docs/api-guide/settings.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ The string that should used for any versioning parameters, such as in the media
163163

164164
Default: `'version'`
165165

166+
#### DEFAULT_VERSIONING_CLASS
167+
168+
The default versioning scheme to use.
169+
170+
Default: `None`
171+
166172
---
167173

168174
## Authentication settings

docs/api-guide/viewsets.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,16 @@ To view all extra actions, call the `.get_extra_actions()` method.
201201
Extra actions can map additional HTTP methods to separate `ViewSet` methods. For example, the above password set/unset methods could be consolidated into a single route. Note that additional mappings do not accept arguments.
202202

203203
```python
204-
@action(detail=True, methods=['put'], name='Change Password')
205-
def password(self, request, pk=None):
206-
"""Update the user's password."""
207-
...
208-
209-
@password.mapping.delete
210-
def delete_password(self, request, pk=None):
211-
"""Delete the user's password."""
212-
...
204+
@action(detail=True, methods=["put"], name="Change Password")
205+
def password(self, request, pk=None):
206+
"""Update the user's password."""
207+
...
208+
209+
210+
@password.mapping.delete
211+
def delete_password(self, request, pk=None):
212+
"""Delete the user's password."""
213+
...
213214
```
214215

215216
## Reversing action URLs
@@ -220,14 +221,14 @@ Note that the `basename` is provided by the router during `ViewSet` registration
220221

221222
Using the example from the previous section:
222223

223-
```python
224-
>>> view.reverse_action('set-password', args=['1'])
224+
```pycon
225+
>>> view.reverse_action("set-password", args=["1"])
225226
'http://localhost:8000/api/users/1/set_password'
226227
```
227228

228229
Alternatively, you can use the `url_name` attribute set by the `@action` decorator.
229230

230-
```python
231+
```pycon
231232
>>> view.reverse_action(view.set_password.url_name, args=['1'])
232233
'http://localhost:8000/api/users/1/set_password'
233234
```

docs/community/3.10-announcement.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ update your REST framework settings to include `DEFAULT_SCHEMA_CLASS` explicitly
4141

4242
```python
4343
REST_FRAMEWORK = {
44-
...
45-
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
44+
...: ...,
45+
"DEFAULT_SCHEMA_CLASS": "rest_framework.schemas.coreapi.AutoSchema",
4646
}
4747
```
4848

@@ -74,10 +74,11 @@ urlpatterns = [
7474
# Use the `get_schema_view()` helper to add a `SchemaView` to project URLs.
7575
# * `title` and `description` parameters are passed to `SchemaGenerator`.
7676
# * Provide view name for use with `reverse()`.
77-
path('openapi', get_schema_view(
78-
title="Your Project",
79-
description="API for all things …"
80-
), name='openapi-schema'),
77+
path(
78+
"openapi",
79+
get_schema_view(title="Your Project", description="API for all things …"),
80+
name="openapi-schema",
81+
),
8182
# ...
8283
]
8384
```

docs/community/3.11-announcement.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ be extracted from the class docstring:
4343

4444
```python
4545
class DocStringExampleListView(APIView):
46-
"""
47-
get: A description of my GET operation.
48-
post: A description of my POST operation.
49-
"""
46+
"""
47+
get: A description of my GET operation.
48+
post: A description of my POST operation.
49+
"""
50+
5051
permission_classes = [permissions.IsAuthenticatedOrReadOnly]
5152

5253
def get(self, request, *args, **kwargs):

0 commit comments

Comments
 (0)