8000 Clean ups to datetime formatting · corentinl/django-rest-framework@1106596 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1106596

Browse files
committed
Clean ups to datetime formatting
1 parent 4f7b028 commit 1106596

File tree

9 files changed

+163
-109
lines changed

9 files changed

+163
-109
lines changed

docs/api-guide/fields.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Serializer fields
44

5-
> Each field in a Form class is responsible not only for validating data, but also for "cleaning" it -- normalizing it to a consistent format.
5+
> Each field in a Form class is responsible not only for validating data, but also for "cleaning" it — normalizing it to a consistent format.
66
>
77
> — [Django documentation][cite]
88
@@ -199,10 +199,10 @@ If you want to override this behavior, you'll need to declare the `DateTimeField
199199

200200
**Signature:** `DateTimeField(format=None, input_formats=None)`
201201

202-
* `format` - A string representing the output format. If not specified, the `DATETIME_FORMAT` setting will be used, which defaults to `'iso8601'`.
203-
* `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 `['iso8601']`.
202+
* `format` - A string representing the output format. If not specified, the `DATETIME_FORMAT` setting will be used, which defaults to `'iso-8601'`.
203+
* `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']`.
204204

205-
DateTime format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'is8601'`, which indicates that [ISO 8601][iso8601] style datetimes should be used. (eg `'2013-01-29T12:34:56.000000'`)
205+
DateTime format strings may either be [python strftime formats][strftime] which explicitly specifiy 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.000000'`)
206206

207207
## DateField
208208

@@ -212,10 +212,10 @@ Corresponds to `django.db.models.fields.DateField`
212212

213213
**Signature:** `DateField(format=None, input_formats=None)`
214214

215-
* `format` - A string representing the output format. If not specified, the `DATE_FORMAT` setting will be used, which defaults to `'iso8601'`.
216-
* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `DATE_INPUT_FORMATS` setting will be used, which defaults to `['iso8601']`.
215+
* `format` - A string representing the output format. If not specified, the `DATE_FORMAT` setting will be used, which defaults to `'iso-8601'`.
216+
* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `DATE_INPUT_FORMATS` setting will be used, which defaults to `['iso-8601']`.
217217

218-
Date format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'is8601'`, which indicates that [ISO 8601][iso8601] style dates should be used. (eg `'2013-01-29'`)
218+
Date format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'iso-8601'`, which indicates that [ISO 8601][iso8601] style dates should be used. (eg `'2013-01-29'`)
219219

220220
## TimeField
221221

@@ -227,10 +227,10 @@ Corresponds to `django.db.models.fields.TimeField`
227227

228228
**Signature:** `TimeField(format=None, input_formats=None)`
229229

230-
* `format` - A string representing the output format. If not specified, the `TIME_FORMAT` setting will be used, which defaults to `'iso8601'`.
231-
* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `TIME_INPUT_FORMATS` setting will be used, which defaults to `['iso8601']`.
230+
* `format` - A string representing the output format. If not specified, the `TIME_FORMAT` setting will be used, which defaults to `'iso-8601'`.
231+
* `input_formats` - A list of strings representing the input formats which may be used to parse the date. If not specified, the `TIME_INPUT_FORMATS` setting will be used, which defaults to `['iso-8601']`.
232232

233-
Time format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'is8601'`, which indicates that [ISO 8601][iso8601] style times should be used. (eg `'12:34:56.000000'`)
233+
Time format strings may either be [python strftime formats][strftime] which explicitly specifiy the format, or the special string `'iso-8601'`, which indicates that [ISO 8601][iso8601] style times should be used. (eg `'12:34:56.000000'`)
234234

235235
## IntegerField
236236

docs/api-guide/settings.md

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ The `api_settings` object will check for any user-defined settings, and otherwis
3434

3535
# API Reference
3636

37-
## DEFAULT_RENDERER_CLASSES
37+
## API policy settings
38+
39+
*The following settings control the basic API policies, and are applied to every `APIView` class based view, or `@api_view` function based view.*
40+
41+
#### DEFAULT_RENDERER_CLASSES
3842

3943
A list or tuple of renderer classes, that determines the default set of renderers that may be used when returning a `Response` object.
4044

@@ -45,7 +49,7 @@ Default:
4549
'rest_framework.renderers.BrowsableAPIRenderer',
4650
)
4751

48-
## DEFAULT_PARSER_CLASSES
52+
#### DEFAULT_PARSER_CLASSES
4953

5054
A list or tuple of parser classes, that determines the default set of parsers used when accessing the `request.DATA` property.
5155

@@ -57,7 +61,7 @@ Default:
5761
'rest_framework.parsers.MultiPartParser'
5862
)
5963

60-
## DEFAULT_AUTHENTICATION_CLASSES
64+
#### DEFAULT_AUTHENTICATION_CLASSES
6165

6266
A list or tuple of authentication classes, that determines the default set of authenticators used when accessing the `request.user` or `request.auth` properties.
6367

@@ -68,7 +72,7 @@ Default:
6872
'rest_framework.authentication.BasicAuthentication'
6973
)
7074

71-
## DEFAULT_PERMISSION_CLASSES
75+
#### DEFAULT_PERMISSION_CLASSES
7276

7377
A list or tuple of permission classes, that determines the default set of permissions checked at the start of a view.
7478

@@ -78,136 +82,164 @@ Default:
7882
'rest_framework.permissions.AllowAny',
7983
)
8084

81-
## DEFAULT_THROTTLE_CLASSES
85+
#### DEFAULT_THROTTLE_CLASSES
8286

8387
A list or tuple of throttle classes, that determines the default set of throttles checked at the start of a view.
8488

8589
Default: `()`
8690

87-
## DEFAULT_CONTENT_NEGOTIATION_CLASS
91+
#### DEFAULT_CONTENT_NEGOTIATION_CLASS
8892

8993
A content negotiation class, that determines how a renderer is selected for the response, given an incoming request.
9094

9195
Default: `'rest_framework.negotiation.DefaultContentNegotiation'`
9296

93-
## DEFAULT_MODEL_SERIALIZER_CLASS
97+
---
98+
99+
## Generic view settings
100+
101+
*The following settings control the behavior of the generic class based views.*
102+
103+
#### DEFAULT_MODEL_SERIALIZER_CLASS
94104

95105
A class that determines the default type of model serializer that should be used by a generic view if `model` is specified, but `serializer_class` is not provided.
96106

97107
Default: `'rest_framework.serializers.ModelSerializer'`
98108

99-
## DEFAULT_PAGINATION_SERIALIZER_CLASS
109+
#### DEFAULT_PAGINATION_SERIALIZER_CLASS
100110

101111
A class the determines the default serialization style for paginated responses.
102112

103113
Default: `rest_framework.pagination.PaginationSerializer`
104114

105-
## FILTER_BACKEND
115+
#### FILTER_BACKEND
106116

107117
The filter backend class that should be used for generic filtering. If set to `None` then generic filtering is disabled.
108118

109-
## PAGINATE_BY
119+
#### PAGINATE_BY
110120

111121
The default page size to use for pagination. If set to `None`, pagination is disabled by default.
112122

113123
Default: `None`
114124

115-
## PAGINATE_BY_PARAM
125+
#### PAGINATE_BY_PARAM
116126

117127
The name of a query parameter, which can be used by the client to overide the default page size to use for pagination. If set to `None`, clients may not override the default page size.
118128

119129
Default: `None`
120130

121-
## UNAUTHENTICATED_USER
131+
---
132+
133+
## Authentication settings
134+
135+
*The following settings control the behavior of unauthenticated requests.*
136+
137+
#### UNAUTHENTICATED_USER
122138

123139
The class that should be used to initialize `request.user` for unauthenticated requests.
124140

125141
Default: `django.contrib.auth.models.AnonymousUser`
126142

127-
## UNAUTHENTICATED_TOKEN
143+
#### UNAUTHENTICATED_TOKEN
128144

129145
The class that should be used to initialize `request.auth` for unauthenticated requests.
130146

131147
Default: `None`
132148

133-
## FORM_METHOD_OVERRIDE
149+
---
150+
151+
## Browser overrides
152+
153+
*The following settings provide URL or form-based overrides of the default browser behavior.*
154+
155+
#### FORM_METHOD_OVERRIDE
134156

135157
The name of a form field that may be used to override the HTTP method of the form.
136158

137159
If the value of this setting is `None` then form method overloading will be disabled.
138160

139161
Default: `'_method'`
140162

141-
## FORM_CONTENT_OVERRIDE
163+
#### FORM_CONTENT_OVERRIDE
142164

143165
The name of a form field that may be used to override the content of the form payload. Must be used together with `FORM_CONTENTTYPE_OVERRIDE`.
144166

145167
If either setting is `None` then form content overloading will be disabled.
146168

147169
Default: `'_content'`
148170

149-
## FORM_CONTENTTYPE_OVERRIDE
171+
#### FORM_CONTENTTYPE_OVERRIDE
150172

151173
The name of a form field that may be used to override the content type of the form payload. Must be used together with `FORM_CONTENT_OVERRIDE`.
152174

153175
If either setting is `None` then form content overloading will be disabled.
154176

155177
Default: `'_content_type'`
156178

157-
## URL_ACCEPT_OVERRIDE
179+
#### URL_ACCEPT_OVERRIDE
158180

159181
The name of a URL parameter that may be used to override the HTTP `Accept` header.
160182

161183
If the value of this setting is `None` then URL accept overloading will be disabled.
162184

163185
Default: `'accept'`
164186

165-
## URL_FORMAT_OVERRIDE
187+
#### URL_FORMAT_OVERRIDE
166188

167189
The name of a URL parameter that may be used to override the default `Accept` header based content negotiation.
168190

169191
Default: `'format'`
170192

171-
## FORMAT_SUFFIX_KWARG
193+
---
172194

173-
The name of a parameter in the URL conf that may be used to provide a format suffix.
195+
## Date/Time formatting
174196

175-
Default: `'format'`
197+
*The following settings are used to control how date and time representations may be parsed and rendered.*
176198

177-
## DATETIME_FORMAT
199+
#### DATETIME_FORMAT
178200

179-
A format string that should be used by default for `DateTimeField` serializer fields.
201+
A format string that should be used by default for rendering the output of `DateTimeField` serializer fields.
180202

181-
Default: `'iso8601'`
203+
Default: `'iso-8601'`
182204

183-
## DATETIME_INPUT_FORMATS
205+
#### DATETIME_INPUT_FORMATS
184206

185207
A list of format strings that should be used by default for parsing inputs to `DateTimeField` serializer fields.
186208

187-
Default: `['iso8601']`
209+
Default: `['iso-8601']`
188210

189-
## DATE_FORMAT
211+
#### DATE_FORMAT
190212

191-
A format string that should be used by default for `DateField` serializer fields.
213+
A format string that should be used by default for rendering the output of `DateField` serializer fields.
192214

193-
Default: `'iso8601'`
215+
Default: `'iso-8601'`
194216

195-
## DATE_INPUT_FORMATS
217+
#### DATE_INPUT_FORMATS
196218

197219
A list of format strings that should be used by default for parsing inputs to `DateField` serializer fields.
198220

199-
Default: `['iso8601']`
221+
Default: `['iso-8601']`
200222

201-
## TIME_FORMAT
223+
#### TIME_FORMAT
202224

203-
A format string that should be used by default for `TimeField` serializer fields.
225+
A format string that should be used by default for rendering the output of `TimeField` serializer fields.
204226

205-
Default: `'iso8601'`
227+
Default: `'iso-8601'`
206228

207-
## TIME_INPUT_FORMATS
229+
#### TIME_INPUT_FORMATS
208230

209231
A list of format strings that should be used by default for parsing inputs to `TimeField` serializer fields.
210232

211-
Default: `['iso8601']`
233+
Default: `['iso-8601']`
234+
235+
---
236+
237+
## Miscellaneous settings
238+
239+
#### FORMAT_SUFFIX_KWARG
240+
241+
The name of a parameter in the URL conf that may be used to provide a format suffix.
242+
243+
Default: `'format'`
212244

213245
[cite]: http://www.python.org/dev/peps/pep-0020/

docs/topics/release-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can determine your currently installed version using `pip freeze`:
4242

4343
### Master
4444

45-
* Support for custom input and output formats for `DateField`, `DateTimeField` and `TimeField`
45+
* Support for custom input and output formats for `DateField`, `DateTimeField` and `TimeField`.
4646
* Cleanup: Request authentication is no longer lazily evaluated, instead authentication is always run, which results in more consistent, obvious behavior. Eg. Supplying bad auth credentials will now always return an error response, even if no permissions are set on the view.
4747
* Bugfix for serializer data being uncacheable with pickle protocol 0.
4848
* Bugfixes for model field validation edge-cases.

rest_framework/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
HTTP_HEADER_ENCODING = 'iso-8859-1'
77

88
# Default input and output format
9-
ISO8601 = 'iso-8601'
9+
ISO_8601 = 'iso-8601'

0 commit comments

Comments
 (0)
0