Skip to content

Commit 3dff9a4

Browse files
committed
Resolve merge conflict
2 parents c06a82d + 1f99612 commit 3dff9a4

File tree

143 files changed

+10944
-2387
lines changed

Some content is hidden

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

143 files changed

+10944
-2387
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bin/
1515
include/
1616
lib/
1717
local/
18+
env/
1819

1920
!.gitignore
2021
!.travis.yml

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ env:
2121
- TOX_ENV=py26-django15
2222
- TOX_ENV=py27-django14
2323
- TOX_ENV=py26-django14
24+
- TOX_ENV=py34-django18alpha
25+
- TOX_ENV=py33-django18alpha
26+
- TOX_ENV=py32-django18alpha
27+
- TOX_ENV=py27-django18alpha
2428
- TOX_ENV=py34-djangomaster
2529
- TOX_ENV=py33-djangomaster
2630
- TOX_ENV=py32-djangomaster

.tx/config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[main]
2+
host = https://www.transifex.com
3+
4+
[django-rest-framework.djangopo]
5+
file_filter = rest_framework/locale/<lang>/LC_MESSAGES/django.po
6+
source_file = rest_framework/locale/en_US/LC_MESSAGES/django.po
7+
source_lang = en_US
8+
type = PO
9+

CONTRIBUTING.md

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ There are many ways you can contribute to Django REST framework. We'd like it t
1010

1111
The most important thing you can do to help push the REST framework project forward is to be actively involved wherever possible. Code contributions are often overvalued as being the primary way to get involved in a project, we don't believe that needs to be the case.
1212

13-
If you use REST framework, we'd love you to be vocal about your experiences with it - you might consider writing a blog post about using REST framework, or publishing a tutorial about building a project with a particular Javascript framework. Experiences from beginners can be particularly helpful because you'll be in the best position to assess which bits of REST framework are more difficult to understand and work with.
13+
If you use REST framework, we'd love you to be vocal about your experiences with it - you might consider writing a blog post about using REST framework, or publishing a tutorial about building a project with a particular JavaScript framework. Experiences from beginners can be particularly helpful because you'll be in the best position to assess which bits of REST framework are more difficult to understand and work with.
1414

15-
Other really great ways you can help move the community forward include helping answer questions on the [discussion group][google-group], or setting up an [email alert on StackOverflow][so-filter] so that you get notified of any new questions with the `django-rest-framework` tag.
15+
Other really great ways you can help move the community forward include helping to answer questions on the [discussion group][google-group], or setting up an [email alert on StackOverflow][so-filter] so that you get notified of any new questions with the `django-rest-framework` tag.
1616

1717
When answering questions make sure to help future contributors find their way around by hyperlinking wherever possible to related threads and tickets, and include backlinks from those items if relevant.
1818

@@ -52,21 +52,55 @@ To start developing on Django REST framework, clone the repo:
5252

5353
git clone git@github.com:tomchristie/django-rest-framework.git
5454

55-
Changes should broadly follow the [PEP 8][pep-8] style conventions, and we recommend you setup your editor to automatically indicated non-conforming styles.
55+
Changes should broadly follow the [PEP 8][pep-8] style conventions, and we recommend you set up your editor to automatically indicate non-conforming styles.
5656

5757
## Testing
5858

5959
To run the tests, clone the repository, and then:
6060

6161
# Setup the virtual environment
6262
virtualenv env
63-
env/bin/activate
63+
source env/bin/activate
6464
pip install -r requirements.txt
6565

6666
# Run the tests
6767
./runtests.py
6868

69-
You can also use the excellent [`tox`][tox] testing tool to run the tests against all supported versions of Python and Django. Install `tox` globally, and then simply run:
69+
### Test options
70+
71+
Run using a more concise output style.
72+
73+
./runtests.py -q
74+
75+
Run the tests using a more concise output style, no coverage, no flake8.
76+
77+
./runtests.py --fast
78+
79+
Don't run the flake8 code linting.
80+
81+
./runtests.py --nolint
82+
83+
Only run the flake8 code linting, don't run the tests.
84+
85+
./runtests.py --lintonly
86+
87+
Run the tests for a given test case.
88+
89+
./runtests.py MyTestCase
90+
91+
Run the tests for a given test method.
92+
93+
./runtests.py MyTestCase.test_this_method
94+
95+
Shorter form to run the tests for a given test method.
96+
97+
./runtests.py test_this_method
98+
99+
Note: The test case and test method matching is fuzzy and will sometimes run other tests that contain a partial string match to the given command line input.
100+
101+
### Running against multiple environments
102+
103+
You can also use the excellent [tox][tox] testing tool to run the tests against all supported versions of Python and Django. Install `tox` globally, and then simply run:
70104

71105
tox
72106

@@ -82,7 +116,7 @@ GitHub's documentation for working on pull requests is [available here][pull-req
82116

83117
Always run the tests before submitting pull requests, and ideally run `tox` in order to check that your modifications are compatible with both Python 2 and Python 3, and that they run properly on all supported versions of Django.
84118

85-
Once you've made a pull request take a look at the travis build status in the GitHub interface and make sure the tests are running as you'd expect.
119+
Once you've made a pull request take a look at the Travis build status in the GitHub interface and make sure the tests are running as you'd expect.
86120

87121
![Travis status][travis-status]
88122

@@ -96,15 +130,15 @@ Sometimes, in order to ensure your code works on various different versions of D
96130

97131
The documentation for REST framework is built from the [Markdown][markdown] source files in [the docs directory][docs].
98132

99-
There are many great markdown editors that make working with the documentation really easy. The [Mou editor for Mac][mou] is one such editor that comes highly recommended.
133+
There are many great Markdown editors that make working with the documentation really easy. The [Mou editor for Mac][mou] is one such editor that comes highly recommended.
100134

101135
## Building the documentation
102136

103137
To build the documentation, install MkDocs with `pip install mkdocs` and then run the following command.
104138

105139
mkdocs build
106140

107-
This will build the html output into the `html` directory.
141+
This will build the documentation into the `site` directory.
108142

109143
You can build the documentation and open a preview in a browser window by using the `serve` command.
110144

@@ -117,8 +151,7 @@ Documentation should be in American English. The tone of the documentation is v
117151
Some other tips:
118152

119153
* Keep paragraphs reasonably short.
120-
* Use double spacing after the end of sentences.
121-
* Don't use the abbreviations such as 'e.g.' but instead use long form, such as 'For example'.
154+
* Don't use abbreviations such as 'e.g.' but instead use the long form, such as 'For example'.
122155

123156
## Markdown style
124157

@@ -151,7 +184,7 @@ If you are hyperlinking to another REST framework document, you should use a rel
151184

152185
[authentication]: ../api-guide/authentication.md
153186

154-
Linking in this style means you'll be able to click the hyperlink in your markdown editor to open the referenced document. When the documentation is built, these links will be converted into regular links to HTML pages.
187+
Linking in this style means you'll be able to click the hyperlink in your Markdown editor to open the referenced document. When the documentation is built, these links will be converted into regular links to HTML pages.
155188

156189
##### 3. Notes
157190

@@ -163,30 +196,16 @@ If you want to draw attention to a note or warning, use a pair of enclosing line
163196

164197
---
165198

166-
# Third party packages
167-
168-
New features to REST framework are generally recommended to be implemented as third party libraries that are developed outside of the core framework. Ideally third party libraries should be properly documented and packaged, and made available on PyPI.
169-
170-
## Getting started
171-
172-
If you have some functionality that you would like to implement as a third party package it's worth contacting the [discussion group][google-group] as others may be willing to get involved. We strongly encourage third party package development and will always try to prioritize time spent helping their development, documentation and packaging.
173-
174-
We recommend the [`django-reusable-app`][django-reusable-app] template as a good resource for getting up and running with implementing a third party Django package.
175-
176-
## Linking to your package
177-
178-
Once your package is decently documented and available on PyPI open a pull request or issue, and we'll add a link to it from the main REST framework documentation.
179199

180200
[cite]: http://www.w3.org/People/Berners-Lee/FAQ.html
181201
[code-of-conduct]: https://www.djangoproject.com/conduct/
182202
[google-group]: https://groups.google.com/forum/?fromgroups#!forum/django-rest-framework
183203
[so-filter]: http://stackexchange.com/filters/66475/rest-framework
184204
[issues]: https://github.com/tomchristie/django-rest-framework/issues?state=open
185205
[pep-8]: http://www.python.org/dev/peps/pep-0008/
186-
[travis-status]: https://raw.github.com/tomchristie/django-rest-framework/master/docs/img/travis-status.png
206+
[travis-status]: ../img/travis-status.png
187207
[pull-requests]: https://help.github.com/articles/using-pull-requests
188208
[tox]: http://tox.readthedocs.org/en/latest/
189209
[markdown]: http://daringfireball.net/projects/markdown/basics
190210
[docs]: https://github.com/tomchristie/django-rest-framework/tree/master/docs
191211
[mou]: http://mouapp.com/
192-
[django-reusable-app]: https://github.com/dabapps/django-reusable-app

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ There is a live example API for testing purposes, [available here][sandbox].
3434
# Requirements
3535

3636
* Python (2.6.5+, 2.7, 3.2, 3.3, 3.4)
37-
* Django (1.4.11+, 1.5.5+, 1.6, 1.7)
37+
* Django (1.4.11+, 1.5.6+, 1.6.3+, 1.7)
3838

3939
# Installation
4040

@@ -156,7 +156,7 @@ Send a description of the issue via email to [rest-framework-security@googlegrou
156156

157157
# License
158158

159-
Copyright (c) 2011-2014, Tom Christie
159+
Copyright (c) 2011-2015, Tom Christie
160160
All rights reserved.
161161

162162
Redistribution and use in source and binary forms, with or without
@@ -190,18 +190,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
190190
[sandbox]: http://restframework.herokuapp.com/
191191

192192
[index]: http://www.django-rest-framework.org/
193-
[oauth1-section]: http://www.django-rest-framework.org/api-guide/authentication.html#oauthauthentication
194-
[oauth2-section]: http://www.django-rest-framework.org/api-guide/authentication.html#oauth2authentication
195-
[serializer-section]: http://www.django-rest-framework.org/api-guide/serializers.html#serializers
196-
[modelserializer-section]: http://www.django-rest-framework.org/api-guide/serializers.html#modelserializer
197-
[functionview-section]: http://www.django-rest-framework.org/api-guide/views.html#function-based-views
198-
[generic-views]: http://www.django-rest-framework.org/api-guide/generic-views.html
199-
[viewsets]: http://www.django-rest-framework.org/api-guide/viewsets.html
200-
[routers]: http://www.django-rest-framework.org/api-guide/routers.html
201-
[serializers]: http://www.django-rest-framework.org/api-guide/serializers.html
202-
[authentication]: http://www.django-rest-framework.org/api-guide/authentication.html
203-
204-
[rest-framework-2-announcement]: http://www.django-rest-framework.org/topics/rest-framework-2-announcement.html
193+
[oauth1-section]: http://www.django-rest-framework.org/api-guide/authentication/#django-rest-framework-oauth
194+
[oauth2-section]: http://www.django-rest-framework.org/api-guide/authentication/#django-oauth-toolkit
195+
[serializer-section]: http://www.django-rest-framework.org/api-guide/serializers/#serializers
196+
[modelserializer-section]: http://www.django-rest-framework.org/api-guide/serializers/#modelserializer
197+
[functionview-section]: http://www.django-rest-framework.org/api-guide/views/#function-based-views
198+
[generic-views]: http://www.django-rest-framework.org/api-guide/generic-views/
199+
[viewsets]: http://www.django-rest-framework.org/api-guide/viewsets/
200+
[routers]: http://www.django-rest-framework.org/api-guide/routers/
201+
[serializers]: http://www.django-rest-framework.org/api-guide/serializers/
202+
[authentication]: http://www.django-rest-framework.org/api-guide/authentication/
203+
[rest-framework-2-announcement]: http://www.django-rest-framework.org/topics/rest-framework-2-announcement/
205204
[2.1.0-notes]: https://groups.google.com/d/topic/django-rest-framework/Vv2M0CMY9bg/discussion
206205
[image]: http://www.django-rest-framework.org/img/quickstart.png
207206

docs/api-guide/authentication.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The value of `request.user` and `request.auth` for unauthenticated requests can
3434

3535
## Setting the authentication scheme
3636

37-
The default authentication schemes may be set globally, using the `DEFAULT_AUTHENTICATION` setting. For example.
37+
The default authentication schemes may be set globally, using the `DEFAULT_AUTHENTICATION_CLASSES` setting. For example.
3838

3939
REST_FRAMEWORK = {
4040
'DEFAULT_AUTHENTICATION_CLASSES': (
@@ -126,7 +126,6 @@ To use the `TokenAuthentication` scheme you'll need to [configure the authentica
126126
'rest_framework.authtoken'
127127
)
128128

129-
130129
---
131130

132131
**Note:** Make sure to run `manage.py syncdb` after changing your settings. The `rest_framework.authtoken` app provides both Django (from v1.7) and South database migrations. See [Schema migrations](#schema-migrations) below.
@@ -249,8 +248,6 @@ Unauthenticated responses that are denied permission will result in an `HTTP 403
249248

250249
If you're using an AJAX style API with SessionAuthentication, you'll need to make sure you include a valid CSRF token for any "unsafe" HTTP method calls, such as `PUT`, `PATCH`, `POST` or `DELETE` requests. See the [Django CSRF documentation][csrf-ajax] for more details.
251250

252-
---
253-
254251
# Custom authentication
255252

256253
To implement a custom authentication scheme, subclass `BaseAuthentication` and override the `.authenticate(self, request)` method. The method should return a two-tuple of `(user, auth)` if authentication succeeds, or `None` otherwise.
@@ -293,13 +290,48 @@ The following example will authenticate any incoming request as the user given b
293290

294291
The following third party packages are also available.
295292

296-
## Digest Authentication
293+
## Django OAuth Toolkit
297294

298-
HTTP digest authentication is a widely implemented scheme that was intended to replace HTTP basic authentication, and which provides a simple encrypted authentication mechanism. [Juan Riaza][juanriaza] maintains the [djangorestframework-digestauth][djangorestframework-digestauth] package which provides HTTP digest authentication support for REST framework.
295+
The [Django OAuth Toolkit][django-oauth-toolkit] package provides OAuth 2.0 support, and works with Python 2.7 and Python 3.3+. The package is maintained by [Evonove][evonove] and uses the excellent [OAuthLib][oauthlib]. The package is well documented, and well supported and is currently our **recommended package for OAuth 2.0 support**.
299296

300-
## Django OAuth Toolkit
297+
#### Installation & configuration
298+
299+
Install using `pip`.
300+
301+
pip install django-oauth-toolkit
302+
303+
Add the package to your `INSTALLED_APPS` and modify your REST framework settings.
304+
305+
INSTALLED_APPS = (
306+
...
307+
'oauth2_provider',
308+
)
309+
310+
REST_FRAMEWORK = {
311+
'DEFAULT_AUTHENTICATION_CLASSES': (
312+
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
313+
)
314+
}
315+
316+
For more details see the [Django REST framework - Getting started][django-oauth-toolkit-getting-started] documentation.
317+
318+
## Django REST framework OAuth
319+
320+
The [Django REST framework OAuth][django-rest-framework-oauth] package provides both OAuth1 and OAuth2 support for REST framework.
321+
322+
This package was previously included directly in REST framework but is now supported and maintained as a third party package.
301323

302-
The [Django OAuth Toolkit][django-oauth-toolkit] package provides OAuth 2.0 support, and works with Python 2.7 and Python 3.3+. The package is maintained by [Evonove][evonove] and uses the excellent [OAuthLib][oauthlib]. The package is well documented, and comes as a recommended alternative for OAuth 2.0 support.
324+
#### Installation & configuration
325+
326+
Install the package using `pip`.
327+
328+
pip install djangorestframework-oauth
329+
330+
For details on configuration and usage see the Django REST framework OAuth documentation for [authentication][django-rest-framework-oauth-authentication] and [permissions][django-rest-framework-oauth-permissions].
331+
332+
## Digest Authentication
333+
334+
HTTP digest authentication is a widely implemented scheme that was intended to replace HTTP basic authentication, and which provides a simple encrypted authentication mechanism. [Juan Riaza][juanriaza] maintains the [djangorestframework-digestauth][djangorestframework-digestauth] package which provides HTTP digest authentication support for REST framework.
303335

304336
## Django OAuth2 Consumer
305337

@@ -328,10 +360,14 @@ HTTP Signature (currently a [IETF draft][http-signature-ietf-draft]) provides a
328360
[oauth]: http://oauth.net/2/
329361
[permission]: permissions.md
330362
[throttling]: throttling.md
331-
[csrf-ajax]: https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax
363+
[csrf-ajax]: https://docs.djangoproject.com/en/dev/ref/csrf/#ajax
332364
[mod_wsgi_official]: http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPassAuthorization
333365
[custom-user-model]: https://docs.djangoproject.com/en/dev/topics/auth/customizing/#specifying-a-custom-user-model
334366
[south-dependencies]: http://south.readthedocs.org/en/latest/dependencies.html
367+
[django-oauth-toolkit-getting-started]: https://django-oauth-toolkit.readthedocs.org/en/latest/rest-framework/getting_started.html
368+
[django-rest-framework-oauth]: http://jpadilla.github.io/django-rest-framework-oauth/
369+
[django-rest-framework-oauth-authentication]: http://jpadilla.github.io/django-rest-framework-oauth/authentication/
370+
[django-rest-framework-oauth-permissions]: http://jpadilla.github.io/django-rest-framework-oauth/permissions/
335371
[juanriaza]: https://github.com/juanriaza
336372
[djangorestframework-digestauth]: https://github.com/juanriaza/django-rest-framework-digestauth
337373
[oauth-1.0a]: http://oauth.net/core/1.0a

docs/api-guide/exceptions.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The handled exceptions are:
1818

1919
In each case, REST framework will return a response with an appropriate status code and content-type. The body of the response will include any additional details regarding the nature of the error.
2020

21-
By default all error responses will include a key `detail` in the body of the response, but other keys may also be included.
21+
Most error responses will include a key `detail` in the body of the response.
2222

2323
For example, the following request:
2424

@@ -33,6 +33,16 @@ Might receive an error response indicating that the `DELETE` method is not allow
3333

3434
{"detail": "Method 'DELETE' not allowed."}
3535

36+
Validation errors are handled slightly differently, and will include the field names as the keys in the response. If the validation error was not specific to a particular field then it will use the "non_field_errors" key, or whatever string value has been set for the `NON_FIELD_ERRORS_KEY` setting.
37+
38+
Any example validation error might look like this:
39+
40+
HTTP/1.1 400 Bad Request
41+
Content-Type: application/json
42+
Content-Length: 94
43+
44+
{"amount": ["A valid integer is required."], "description": ["This field may not be blank."]}
45+
3646
## Custom exception handling
3747

3848
You can implement custom exception handling by creating a handler function that converts exceptions raised in your API views into response objects. This allows you to control the style of error responses used by your API.

0 commit comments

Comments
 (0)