Skip to content

Commit dee5fb5

Browse files
committed
Merge remote-tracking branch 'reference/master' into feature/ipaddress-fix
Conflicts: docs/api-guide/fields.md
2 parents d6effbf + 0c66c7c commit dee5fb5

File tree

127 files changed

+4993
-2468
lines changed

Some content is hidden

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

127 files changed

+4993
-2468
lines changed

.travis.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ sudo: false
55
env:
66
- TOX_ENV=py27-flake8
77
- TOX_ENV=py27-docs
8+
- TOX_ENV=py34-django18
9+
- TOX_ENV=py33-django18
10+
- TOX_ENV=py32-django18
11+
- TOX_ENV=py27-django18
812
- TOX_ENV=py34-django17
913
- TOX_ENV=py33-django17
1014
- TOX_ENV=py32-django17
@@ -21,10 +25,18 @@ env:
2125
- TOX_ENV=py26-django15
2226
- TOX_ENV=py27-django14
2327
- TOX_ENV=py26-django14
24-
- TOX_ENV=py34-django18beta
25-
- TOX_ENV=py33-django18beta
26-
- TOX_ENV=py32-django18beta
27-
- TOX_ENV=py27-django18beta
28+
- TOX_ENV=py27-djangomaster
29+
- TOX_ENV=py32-djangomaster
30+
- TOX_ENV=py33-djangomaster
31+
- TOX_ENV=py34-djangomaster
32+
33+
matrix:
34+
fast_finish: true
35+
allow_failures:
36+
- env: TOX_ENV=py27-djangomaster
37+
- env: TOX_ENV=py32-djangomaster
38+
- env: TOX_ENV=py33-djangomaster
39+
- env: TOX_ENV=py34-djangomaster
2840

2941
install:
3042
- pip install tox

LICENSE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# License
2+
3+
Copyright (c) 2011-2015, Tom Christie
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
Redistributions in binary form must reproduce the above copyright notice, this
12+
list of conditions and the following disclaimer in the documentation and/or
13+
other materials provided with the distribution.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include README.md
2+
include LICENSE.md
13
recursive-include rest_framework/static *.js *.css *.png *.eot *.svg *.ttf *.woff
24
recursive-include rest_framework/templates *.html
35
recursive-exclude * __pycache__

README.md

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Full documentation for the project is available at [http://www.django-rest-frame
99

1010
---
1111

12-
**Note**: We have now released Django REST framework 3.0. For older codebases you may want to refer to the version 2.4.4 [source code](https://github.com/tomchristie/django-rest-framework/tree/version-2.4.x), and [documentation](http://tomchristie.github.io/rest-framework-2-docs/).
12+
**Note**: We have now released Django REST framework 3.1. For older codebases you may want to refer to the version 2.4.4 [source code](https://github.com/tomchristie/django-rest-framework/tree/version-2.4.x), and [documentation](http://tomchristie.github.io/rest-framework-2-docs/).
13+
14+
For more details see the [3.1 release notes][3.1-announcement]
1315

1416
---
1517

@@ -23,7 +25,7 @@ Some reasons you might want to use REST framework:
2325
* [Authentication policies][authentication] including optional packages for [OAuth1a][oauth1-section] and [OAuth2][oauth2-section].
2426
* [Serialization][serializers] that supports both [ORM][modelserializer-section] and [non-ORM][serializer-section] data sources.
2527
* Customizable all the way down - just use [regular function-based views][functionview-section] if you don't need the [more][generic-views] [powerful][viewsets] [features][routers].
26-
* [Extensive documentation][index], and [great community support][group].
28+
* [Extensive documentation][docs], and [great community support][group].
2729

2830
There is a live example API for testing purposes, [available here][sandbox].
2931

@@ -34,7 +36,7 @@ There is a live example API for testing purposes, [available here][sandbox].
3436
# Requirements
3537

3638
* Python (2.6.5+, 2.7, 3.2, 3.3, 3.4)
37-
* Django (1.4.11+, 1.5.6+, 1.6.3+, 1.7, 1.8-beta)
39+
* Django (1.4.11+, 1.5.6+, 1.6.3+, 1.7, 1.8)
3840

3941
# Installation
4042

@@ -154,42 +156,15 @@ If you believe you’ve found something in Django REST framework which has secur
154156

155157
Send a description of the issue via email to [[email protected]][security-mail]. The project maintainers will then work with you to resolve any issues where required, prior to any public disclosure.
156158

157-
# License
158-
159-
Copyright (c) 2011-2015, Tom Christie
160-
All rights reserved.
161-
162-
Redistribution and use in source and binary forms, with or without
163-
modification, are permitted provided that the following conditions are met:
164-
165-
Redistributions of source code must retain the above copyright notice, this
166-
list of conditions and the following disclaimer.
167-
Redistributions in binary form must reproduce the above copyright notice, this
168-
list of conditions and the following disclaimer in the documentation and/or
169-
other materials provided with the distribution.
170-
171-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
172-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
173-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
174-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
175-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
176-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
177-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
178-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
179-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
180-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
181-
182159

183160
[build-status-image]: https://secure.travis-ci.org/tomchristie/django-rest-framework.svg?branch=master
184161
[travis]: http://travis-ci.org/tomchristie/django-rest-framework?branch=master
185-
[pypi-version]: https://pypip.in/version/djangorestframework/badge.svg
162+
[pypi-version]: https://img.shields.io/pypi/v/djangorestframework.svg
186163
[pypi]: https://pypi.python.org/pypi/djangorestframework
187164
[twitter]: https://twitter.com/_tomchristie
188165
[group]: https://groups.google.com/forum/?fromgroups#!forum/django-rest-framework
189-
[0.4]: https://github.com/tomchristie/django-rest-framework/tree/0.4.X
190166
[sandbox]: http://restframework.herokuapp.com/
191167

192-
[index]: http://www.django-rest-framework.org/
193168
[oauth1-section]: http://www.django-rest-framework.org/api-guide/authentication/#django-rest-framework-oauth
194169
[oauth2-section]: http://www.django-rest-framework.org/api-guide/authentication/#django-oauth-toolkit
195170
[serializer-section]: http://www.django-rest-framework.org/api-guide/serializers/#serializers
@@ -200,18 +175,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
200175
[routers]: http://www.django-rest-framework.org/api-guide/routers/
201176
[serializers]: http://www.django-rest-framework.org/api-guide/serializers/
202177
[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/
204-
[2.1.0-notes]: https://groups.google.com/d/topic/django-rest-framework/Vv2M0CMY9bg/discussion
205178
[image]: http://www.django-rest-framework.org/img/quickstart.png
206179

207-
[tox]: http://testrun.org/tox/latest/
208-
209-
[tehjones]: https://twitter.com/tehjones/status/294986071979196416
210-
[wlonk]: https://twitter.com/wlonk/status/261689665952833536
211-
[laserllama]: https://twitter.com/laserllama/status/328688333750407168
212-
213180
[docs]: http://www.django-rest-framework.org/
214-
[urlobject]: https://github.com/zacharyvoase/urlobject
215-
[markdown]: http://pypi.python.org/pypi/Markdown/
216-
[django-filter]: http://pypi.python.org/pypi/django-filter
217181
[security-mail]: mailto:[email protected]
182+
[3.1-announcement]: http://www.django-rest-framework.org/topics/3.1-announcement/

docs/api-guide/authentication.md

100755100644
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ The `curl` command line tool may be useful for testing token authenticated APIs.
168168
If you want every user to have an automatically generated Token, you can simply catch the User's `post_save` signal.
169169

170170
from django.conf import settings
171-
from django.contrib.auth import get_user_model
172171
from django.db.models.signals import post_save
173172
from django.dispatch import receiver
174173
from rest_framework.authtoken.models import Token
@@ -248,6 +247,10 @@ Unauthenticated responses that are denied permission will result in an `HTTP 403
248247

249248
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.
250249

250+
**Warning**: Always use Django's standard login view when creating login pages. This will ensure your login views are properly protected.
251+
252+
CSRF validation in REST framework works slightly differently to standard Django due to the need to support both session and non-session based authentication to the same views. This means that only authenticated requests require CSRF tokens, and anonymous requests may be sent without CSRF tokens. This behaviour is not suitable for login views, which should always have CSRF validation applied.
253+
251254
# Custom authentication
252255

253256
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.

docs/api-guide/fields.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
source: fields.py
22

3-
---
4-
5-
**Note**: This is the documentation for the **version 3.0** of REST framework. Documentation for [version 2.4](http://tomchristie.github.io/rest-framework-2-docs/) is also available.
6-
7-
---
8-
93
# Serializer fields
104

115
> Each field in a Form class is responsible not only for validating data, but also for "cleaning" it — normalizing it to a consistent format.
@@ -189,6 +183,15 @@ A field that ensures the input is a valid UUID string. The `to_internal_value` m
189183

190184
"de305d54-75b4-431b-adb2-eb6b9e546013"
191185

186+
**Signature:** `UUIDField(format='hex_verbose')`
187+
188+
- `format`: Determines the representation format of the uuid value
189+
- `'hex_verbose'` - The cannoncical hex representation, including hyphens: `"5ce0e9a5-5ffa-654b-cee0-1238041fb31a"`
190+
- `'hex'` - The compact hex representation of the UUID, not including hyphens: `"5ce0e9a55ffa654bcee01238041fb31a"`
191+
- `'int'` - A 128 bit integer representation of the UUID: `"123456789012312313134124512351145145114"`
192+
- `'urn'` - RFC 4122 URN representation of the UUID: `"urn:uuid:5ce0e9a5-5ffa-654b-cee0-1238041fb31a"`
193+
Changing the `format` parameters only affects representation values. All formats are accepted by `to_internal_value`
194+
192195
## IPAddressField
193196

194197
A field that ensures the input is a valid IPv4 or IPv6 string.
@@ -319,6 +322,18 @@ Corresponds to `django.db.models.fields.TimeField`
319322

320323
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 times should be used. (eg `'12:34:56.000000'`)
321324

325+
## DurationField
326+
327+
A Duration representation.
328+
Corresponds to `django.db.models.fields.DurationField`
329+
330+
The `validated_data` for these fields will contain a `datetime.timedelta` instance.
331+
The representation is a string following this format `'[DD] [HH:[MM:]]ss[.uuuuuu]'`.
332+
333+
**Note:** This field is only available with Django versions >= 1.8.
334+
335+
**Signature:** `DurationField()`
336+
322337
---
323338

324339
# Choice selection fields
@@ -451,7 +466,7 @@ A field class that does not take a value based on user input, but instead takes
451466

452467
For example, to include a field that always provides the current time as part of the serializer validated data, you would use the following:
453468

454-
modified = serializer.HiddenField(default=timezone.now)
469+
modified = serializers.HiddenField(default=timezone.now)
455470

456471
The `HiddenField` class is usually only needed if you have some validation that needs to run based on some pre-provided field values, but you do not want to expose all of those fields to the end user.
457472

@@ -498,7 +513,7 @@ If you want to create a custom field, you'll need to subclass `Field` and then o
498513

499514
The `.to_representation()` method is called to convert the initial datatype into a primitive, serializable datatype.
500515

501-
The `to_internal_value()` method is called to restore a primitive datatype into its internal python representation. This method should raise a `serializer.ValidationError` if the data is invalid.
516+
The `to_internal_value()` method is called to restore a primitive datatype into its internal python representation. This method should raise a `serializers.ValidationError` if the data is invalid.
502517

503518
Note that the `WritableField` class that was present in version 2.x no longer exists. You should subclass `Field` and override `to_internal_value()` if the field supports data input.
504519

docs/api-guide/filtering.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ We can override `.get_queryset()` to deal with URLs such as `http://example.com/
7272
by filtering against a `username` query parameter in the URL.
7373
"""
7474
queryset = Purchase.objects.all()
75-
username = self.request.QUERY_PARAMS.get('username', None)
75+
username = self.request.query_params.get('username', None)
7676
if username is not None:
7777
queryset = queryset.filter(purchaser__username=username)
7878
return queryset
@@ -395,6 +395,10 @@ The following third party packages provide additional filter implementations.
395395

396396
The [django-rest-framework-filters package][django-rest-framework-filters] works together with the `DjangoFilterBackend` class, and allows you to easily create filters across relationships, or create multiple filter lookup types for a given field.
397397

398+
## Django REST framework full word search filter
399+
400+
The [djangorestframework-word-filter][django-rest-framework-word-search-filter] developed as alternative to `filters.SearchFilter` which will search full word in text, or exact match.
401+
398402
[cite]: https://docs.djangoproject.com/en/dev/topics/db/queries/#retrieving-specific-objects-with-filters
399403
[django-filter]: https://github.com/alex/django-filter
400404
[django-filter-docs]: https://django-filter.readthedocs.org/en/latest/index.html
@@ -404,3 +408,4 @@ The [django-rest-framework-filters package][django-rest-framework-filters] works
404408
[nullbooleanselect]: https://github.com/django/django/blob/master/django/forms/widgets.py
405409
[search-django-admin]: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields
406410
[django-rest-framework-filters]: https://github.com/philipn/django-rest-framework-filters
411+
[django-rest-framework-word-search-filter]: https://github.com/trollknurr/django-rest-framework-word-search-filter

docs/api-guide/generic-views.md

100755100644
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
source: mixins.py
22
generics.py
33

4-
---
5-
6-
**Note**: This is the documentation for the **version 3.0** of REST framework. Documentation for [version 2.4](http://tomchristie.github.io/rest-framework-2-docs/) is also available.
7-
8-
---
9-
104
# Generic views
115

126
> Django’s generic views... were developed as a shortcut for common usage patterns... They take certain common idioms and patterns found in view development and abstract them so that you can quickly write common views of data without having to repeat yourself.
@@ -57,7 +51,7 @@ For more complex cases you might also want to override various methods on the vi
5751

5852
For very simple cases you might want to pass through any class attributes using the `.as_view()` method. For example, your URLconf might include something like the following entry:
5953

60-
url(r'^/users/', ListCreateAPIView.as_view(model=User), name='user-list')
54+
url(r'^/users/', ListCreateAPIView.as_view(queryset=User.objects.all(), serializer_class=UserSerializer), name='user-list')
6155

6256
---
6357

@@ -84,10 +78,9 @@ The following attributes control the basic view behavior.
8478

8579
The following attributes are used to control pagination when used with list views.
8680

87-
* `paginate_by` - The size of pages to use with paginated data. If set to `None` then pagination is turned off. If unset this uses the same value as the `PAGINATE_BY` setting, which defaults to `None`.
88-
* `paginate_by_param` - The name of a query parameter, which can be used by the client to override the default page size to use for pagination. If unset this uses the same value as the `PAGINATE_BY_PARAM` setting, which defaults to `None`.
89-
* `pagination_serializer_class` - The pagination serializer class to use when determining the style of paginated responses. Defaults to the same value as the `DEFAULT_PAGINATION_SERIALIZER_CLASS` setting.
90-
* `page_kwarg` - The name of a URL kwarg or URL query parameter which can be used by the client to control which page is requested. Defaults to `'page'`.
81+
* `pagination_class` - The pagination class that should be used when paginating list results. Defaults to the same value as the `DEFAULT_PAGINATION_CLASS` setting, which is `'rest_framework.pagination.PageNumberPagination'`.
82+
83+
Note that usage of the `paginate_by`, `paginate_by_param` and `page_kwarg` attributes are now pending deprecation. The `pagination_serializer_class` attribute and `DEFAULT_PAGINATION_SERIALIZER_CLASS` setting have been removed completely. Pagination settings should instead be controlled by overriding a pagination class and setting any configuration attributes there. See the pagination documentation for more details.
9184

9285
**Filtering**:
9386

@@ -135,14 +128,14 @@ Note that if your API doesn't include any object level permissions, you may opti
135128

136129
Returns the classes that should be used to filter the queryset. Defaults to returning the `filter_backends` attribute.
137130

138-
May be overridden to provide more complex behavior with filters, such as using different (or even exlusive) lists of filter_backends depending on different criteria.
131+
May be overridden to provide more complex behavior with filters, such as using different (or even exclusive) lists of filter_backends depending on different criteria.
139132

140133
For example:
141134

142135
def get_filter_backends(self):
143-
if "geo_route" in self.request.QUERY_PARAMS:
136+
if "geo_route" in self.request.query_params:
144137
return (GeoRouteFilter, CategoryFilter)
145-
elif "geo_point" in self.request.QUERY_PARAMS:
138+
elif "geo_point" in self.request.query_params:
146139
return (GeoPointFilter, CategoryFilter)
147140

148141
return (CategoryFilter,)
@@ -200,7 +193,7 @@ You won't typically need to override the following methods, although you might n
200193

201194
* `get_serializer_context(self)` - Returns a dictionary containing any extra context that should be supplied to the serializer. Defaults to including `'request'`, `'view'` and `'format'` keys.
202195
* `get_serializer(self, instance=None, data=None, files=None, many=False, partial=False, allow_add_remove=False)` - Returns a serializer instance.
203-
* `get_pagination_serializer(self, page)` - Returns a serializer instance to use with paginated data.
196+
* `get_paginated_response(self, data)` - Returns a paginated style `Response` object.
204197
* `paginate_queryset(self, queryset)` - Paginate a queryset if required, either returning a page object, or `None` if pagination is not configured for this view.
205198
* `filter_queryset(self, queryset)` - Given a queryset, filter it with whichever filter backends are in use, returning a new queryset.
206199

docs/api-guide/metadata.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
source: metadata.py
22

3-
---
4-
5-
**Note**: This is the documentation for the **version 3.0** of REST framework. Documentation for [version 2.4](http://tomchristie.github.io/rest-framework-2-docs/) is also available.
6-
7-
---
8-
93
# Metadata
104

115
> [The `OPTIONS`] method allows a client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.
@@ -59,7 +53,7 @@ Or you can set the metadata class individually for a view:
5953

6054
class APIRoot(APIView):
6155
metadata_class = APIRootMetadata
62-
56+
6357
def get(self, request, format=None):
6458
return Response({
6559
...

0 commit comments

Comments
 (0)