Skip to content

Commit 1c1f1de

Browse files
committed
Style notes using admonition in the documentation
https://python-markdown.github.io/extensions/admonition/
1 parent 3a70eb2 commit 1c1f1de

File tree

14 files changed

+103
-151
lines changed

14 files changed

+103
-151
lines changed

docs/api-guide/content-negotiation.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ If the requested view was only configured with renderers for `YAML` and `HTML`,
3434

3535
For more information on the `HTTP Accept` header, see [RFC 2616][accept-header]
3636

37-
---
38-
39-
**Note**: "q" values are not taken into account by REST framework when determining preference. The use of "q" values negatively impacts caching, and in the author's opinion they are an unnecessary and overcomplicated approach to content negotiation.
4037

41-
This is a valid approach as the HTTP spec deliberately underspecifies how a server should weight server-based preferences against client-based preferences.
38+
!!! note
39+
"q" values are not taken into account by REST framework when determining preference. The use of "q" values negatively impacts caching, and in the author's opinion they are an unnecessary and overcomplicated approach to content negotiation.
4240

43-
---
41+
This is a valid approach as the HTTP spec deliberately underspecifies how a server should weight server-based preferences against client-based preferences.
4442

4543
# Custom content negotiation
4644

docs/api-guide/parsers.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ REST framework includes a number of built-in Parser classes, that allow you to a
1717

1818
The set of valid parsers for a view is always defined as a list of classes. When `request.data` is accessed, REST framework will examine the `Content-Type` header on the incoming request, and determine which parser to use to parse the request content.
1919

20-
---
21-
22-
**Note**: When developing client applications always remember to make sure you're setting the `Content-Type` header when sending data in an HTTP request.
20+
!!! note
21+
When developing client applications always remember to make sure you're setting the `Content-Type` header when sending data in an HTTP request.
2322

24-
If you don't set the content type, most clients will default to using `'application/x-www-form-urlencoded'`, which may not be what you wanted.
23+
If you don't set the content type, most clients will default to using `'application/x-www-form-urlencoded'`, which may not be what you wanted.
2524

26-
As an example, if you are sending `json` encoded data using jQuery with the [.ajax() method][jquery-ajax], you should make sure to include the `contentType: 'application/json'` setting.
27-
28-
---
25+
As an example, if you are sending `json` encoded data using jQuery with the [.ajax() method][jquery-ajax], you should make sure to include the `contentType: 'application/json'` setting.
2926

3027
## Setting the parsers
3128

docs/api-guide/permissions.md

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,15 @@ For example:
5151
self.check_object_permissions(self.request, obj)
5252
return obj
5353

54-
---
55-
56-
**Note**: With the exception of `DjangoObjectPermissions`, the provided
57-
permission classes in `rest_framework.permissions` **do not** implement the
58-
methods necessary to check object permissions.
54+
!!! note
55+
With the exception of `DjangoObjectPermissions`, the provided
56+
permission classes in `rest_framework.permissions` **do not** implement the
57+
methods necessary to check object permissions.
5958

60-
If you wish to use the provided permission classes in order to check object
61-
permissions, **you must** subclass them and implement the
62-
`has_object_permission()` method described in the [_Custom
63-
permissions_](#custom-permissions) section (below).
64-
65-
---
59+
If you wish to use the provided permission classes in order to check object
60+
permissions, **you must** subclass them and implement the
61+
`has_object_permission()` method described in the [_Custom
62+
permissions_](#custom-permissions) section (below).
6663

6764
#### Limitations of object level permissions
6865

@@ -118,7 +115,8 @@ Or, if you're using the `@api_view` decorator with function based views.
118115
}
119116
return Response(content)
120117

121-
__Note:__ when you set new permission classes via the class attribute or decorators you're telling the view to ignore the default list set in the __settings.py__ file.
118+
!!! note
119+
When you set new permission classes via the class attribute or decorators you're telling the view to ignore the default list set in the ``settings.py`` file.
122120

123121
Provided they inherit from `rest_framework.permissions.BasePermission`, permissions can be composed using standard Python bitwise operators. For example, `IsAuthenticatedOrReadOnly` could be written:
124122

@@ -131,17 +129,16 @@ Provided they inherit from `rest_framework.permissions.BasePermission`, permissi
131129
return request.method in SAFE_METHODS
132130

133131
class ExampleView(APIView):
134-
permission_classes = [IsAuthenticated|ReadOnly]
132+
permission_classes = [IsAuthenticated | ReadOnly]
135133

136134
def get(self, request, format=None):
137135
content = {
138136
'status': 'request was permitted'
139137
}
140138
return Response(content)
141139

142-
__Note:__ it supports & (and), | (or) and ~ (not).
143-
144-
---
140+
!!! note
141+
Composition of permissions supports `&` (and), `|` (or) and `~` (not) operators.
145142

146143
# API Reference
147144

@@ -185,7 +182,7 @@ To use custom model permissions, override `DjangoModelPermissions` and set the `
185182

186183
Similar to `DjangoModelPermissions`, but also allows unauthenticated users to have read-only access to the API.
187184

188-
## DjangoObjectPermissions
185+
## DjangoObjectPermissions
189186

190187
This permission class ties into Django's standard [object permissions framework][objectpermissions] that allows per-object permissions on models. In order to use this permission class, you'll also need to add a permission backend that supports object-level permissions, such as [django-guardian][guardian].
191188

@@ -199,11 +196,8 @@ Note that `DjangoObjectPermissions` **does not** require the `django-guardian` p
199196

200197
As with `DjangoModelPermissions` you can use custom model permissions by overriding `DjangoObjectPermissions` and setting the `.perms_map` property. Refer to the source code for details.
201198

202-
---
203-
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-
206-
---
199+
!!! note
200+
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.
207201

208202
# Custom permissions
209203

@@ -221,11 +215,8 @@ If you need to test if a request is a read operation or a write operation, you s
221215
else:
222216
# Check permissions for write request
223217

224-
---
225-
226-
**Note**: The instance-level `has_object_permission` method will only be called if the view-level `has_permission` checks have already passed. Also note that in order for the instance-level checks to run, the view code should explicitly call `.check_object_permissions(request, obj)`. If you are using the generic views then this will be handled for you by default. (Function-based views will need to check object permissions explicitly, raising `PermissionDenied` on failure.)
227-
228-
---
218+
!!! note
219+
The instance-level `has_object_permission` method will only be called if the view-level `has_permission` checks have already passed. Also note that in order for the instance-level checks to run, the view code should explicitly call `.check_object_permissions(request, obj)`. If you are using the generic views then this will be handled for you by default. (Function-based views will need to check object permissions explicitly, raising `PermissionDenied` on failure.)
229220

230221
Custom permissions will raise a `PermissionDenied` exception if the test fails. To change the error message associated with the exception, implement a `message` attribute directly on your custom permission. Otherwise the `default_detail` attribute from `PermissionDenied` will be used. Similarly, to change the code identifier associated with the exception, implement a `code` attribute directly on your custom permission - otherwise the `default_code` attribute from `PermissionDenied` will be used.
231222

docs/api-guide/relations.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,12 @@ Would serialize to a representation like this:
183183

184184
By default this field is read-write, although you can change this behavior using the `read_only` flag.
185185

186-
---
187-
188-
**Note**: This field is designed for objects that map to a URL that accepts a single URL keyword argument, as set using the `lookup_field` and `lookup_url_kwarg` arguments.
186+
!!! note
187+
This field is designed for objects that map to a URL that accepts a single URL keyword argument, as set using the `lookup_field` and `lookup_url_kwarg` arguments.
189188

190-
This is suitable for URLs that contain a single primary key or slug argument as part of the URL.
189+
This is suitable for URLs that contain a single primary key or slug argument as part of the URL.
191190

192-
If you require more complex hyperlinked representation you'll need to customize the field, as described in the [custom hyperlinked fields](#custom-hyperlinked-fields) section, below.
193-
194-
---
191+
If you require more complex hyperlinked representation you'll need to customize the field, as described in the [custom hyperlinked fields](#custom-hyperlinked-fields) section, below.
195192

196193
**Arguments**:
197194

docs/api-guide/renderers.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,16 @@ This renderer is suitable for CRUD-style web APIs that should also present a use
202202

203203
Note that views that have nested or list serializers for their input won't work well with the `AdminRenderer`, as the HTML forms are unable to properly support them.
204204

205-
**Note**: The `AdminRenderer` is only able to include links to detail pages when a properly configured `URL_FIELD_NAME` (`url` by default) attribute is present in the data. For `HyperlinkedModelSerializer` this will be the case, but for `ModelSerializer` or plain `Serializer` classes you'll need to make sure to include the field explicitly. For example here we use models `get_absolute_url` method:
205+
!!! note
206+
The `AdminRenderer` is only able to include links to detail pages when a properly configured `URL_FIELD_NAME` (`url` by default) attribute is present in the data. For `HyperlinkedModelSerializer` this will be the case, but for `ModelSerializer` or plain `Serializer` classes you'll need to make sure to include the field explicitly.
206207

207-
class AccountSerializer(serializers.ModelSerializer):
208-
url = serializers.CharField(source='get_absolute_url', read_only=True)
208+
For example here we use models `get_absolute_url` method:
209209

210-
class Meta:
211-
model = Account
210+
class AccountSerializer(serializers.ModelSerializer):
211+
url = serializers.CharField(source='get_absolute_url', read_only=True)
212+
213+
class Meta:
214+
model = Account
212215

213216

214217
**.media_type**: `text/html`
@@ -390,9 +393,8 @@ Exceptions raised and handled by an HTML renderer will attempt to render using o
390393

391394
Templates will render with a `RequestContext` which includes the `status_code` and `details` keys.
392395

393-
**Note**: If `DEBUG=True`, Django's standard traceback error page will be displayed instead of rendering the HTTP status code and text.
394-
395-
---
396+
!!! note
397+
If `DEBUG=True`, Django's standard traceback error page will be displayed instead of rendering the HTTP status code and text.
396398

397399
# Third party packages
398400

docs/api-guide/routers.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,14 @@ The example above would generate the following URL patterns:
4040
* URL pattern: `^accounts/$` Name: `'account-list'`
4141
* URL pattern: `^accounts/{pk}/$` Name: `'account-detail'`
4242

43-
---
44-
45-
**Note**: The `basename` argument is used to specify the initial part of the view name pattern. In the example above, that's the `user` or `account` part.
43+
!!! note
44+
The `basename` argument is used to specify the initial part of the view name pattern. In the example above, that's the `user` or `account` part.
4645

47-
Typically you won't *need* to specify the `basename` argument, but if you have a viewset where you've defined a custom `get_queryset` method, then the viewset may not have a `.queryset` attribute set. If you try to register that viewset you'll see an error like this:
46+
Typically you won't *need* to specify the `basename` argument, but if you have a viewset where you've defined a custom `get_queryset` method, then the viewset may not have a `.queryset` attribute set. If you try to register that viewset you'll see an error like this:
4847

49-
'basename' argument not specified, and could not automatically determine the name from the viewset, as it does not have a '.queryset' attribute.
48+
'basename' argument not specified, and could not automatically determine the name from the viewset, as it does not have a '.queryset' attribute.
5049

51-
This means you'll need to explicitly set the `basename` argument when registering the viewset, as it could not be automatically determined from the model name.
52-
53-
---
50+
This means you'll need to explicitly set the `basename` argument when registering the viewset, as it could not be automatically determined from the model name.
5451

5552
### Using `include` with routers
5653

@@ -91,16 +88,13 @@ Or both an application and instance namespace:
9188

9289
See Django's [URL namespaces docs][url-namespace-docs] and the [`include` API reference][include-api-reference] for more details.
9390

94-
---
95-
96-
**Note**: If using namespacing with hyperlinked serializers you'll also need to ensure that any `view_name` parameters
97-
on the serializers correctly reflect the namespace. In the examples above you'd need to include a parameter such as
98-
`view_name='app_name:user-detail'` for serializer fields hyperlinked to the user detail view.
99-
100-
The automatic `view_name` generation uses a pattern like `%(model_name)-detail`. Unless your models names actually clash
101-
you may be better off **not** namespacing your Django REST Framework views when using hyperlinked serializers.
102-
103-
---
91+
!!! note
92+
If using namespacing with hyperlinked serializers you'll also need to ensure that any `view_name` parameters
93+
on the serializers correctly reflect the namespace. In the examples above you'd need to include a parameter such as
94+
`view_name='app_name:user-detail'` for serializer fields hyperlinked to the user detail view.
95+
96+
The automatic `view_name` generation uses a pattern like `%(model_name)-detail`. Unless your models names actually clash
97+
you may be better off **not** namespacing your Django REST Framework views when using hyperlinked serializers.
10498

10599
### Routing for extra actions
106100

docs/api-guide/schemas.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,12 @@ operation = auto_schema.get_operation(...)
238238
In compiling the schema, `SchemaGenerator` calls `get_components()` and
239239
`get_operation()` for each view, allowed method, and path.
240240

241-
----
242-
243-
**Note**: The automatic introspection of components, and many operation
244-
parameters relies on the relevant attributes and methods of
245-
`GenericAPIView`: `get_serializer()`, `pagination_class`, `filter_backends`,
246-
etc. For basic `APIView` subclasses, default introspection is essentially limited to
247-
the URL kwarg path parameters for this reason.
248-
249-
----
241+
!!! note
242+
The automatic introspection of components, and many operation
243+
parameters relies on the relevant attributes and methods of
244+
`GenericAPIView`: `get_serializer()`, `pagination_class`, `filter_backends`,
245+
etc. For basic `APIView` subclasses, default introspection is essentially limited to
246+
the URL kwarg path parameters for this reason.
250247

251248
`AutoSchema` encapsulates the view introspection needed for schema generation.
252249
Because of this all the schema generation logic is kept in a single place,

docs/api-guide/serializers.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,20 +542,16 @@ This option should be a list or tuple of field names, and is declared as follows
542542

543543
Model fields which have `editable=False` set, and `AutoField` fields will be set to read-only by default, and do not need to be added to the `read_only_fields` option.
544544

545-
---
546-
547-
**Note**: There is a special-case where a read-only field is part of a `unique_together` constraint at the model level. In this case the field is required by the serializer class in order to validate the constraint, but should also not be editable by the user.
548-
549-
The right way to deal with this is to specify the field explicitly on the serializer, providing both the `read_only=True` and `default=…` keyword arguments.
545+
!!! note
546+
There is a special-case where a read-only field is part of a `unique_together` constraint at the model level. In this case the field is required by the serializer class in order to validate the constraint, but should also not be editable by the user.
550547

551-
One example of this is a read-only relation to the currently authenticated `User` which is `unique_together` with another identifier. In this case you would declare the user field like so:
548+
The right way to deal with this is to specify the field explicitly on the serializer, providing both the `read_only=True` and `default=…` keyword arguments.
552549

553-
user = serializers.PrimaryKeyRelatedField(read_only=True, default=serializers.CurrentUserDefault())
550+
One example of this is a read-only relation to the currently authenticated `User` which is `unique_together` with another identifier. In this case you would declare the user field like so:
554551

555-
Please review the [Validators Documentation](/api-guide/validators/) for details on the [UniqueTogetherValidator](/api-guide/validators/#uniquetogethervalidator) and [CurrentUserDefault](/api-guide/validators/#currentuserdefault) classes.
556-
557-
---
552+
user = serializers.PrimaryKeyRelatedField(read_only=True, default=serializers.CurrentUserDefault())
558553

554+
Please review the [Validators Documentation](/api-guide/validators/) for details on the [UniqueTogetherValidator](/api-guide/validators/#uniquetogethervalidator) and [CurrentUserDefault](/api-guide/validators/#currentuserdefault) classes.
559555

560556
## Additional keyword arguments
561557

0 commit comments

Comments
 (0)