diff --git a/.travis.yml b/.travis.yml index b2da9e816..7f1fda837 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ python: - "3.4" env: - - DJANGO="https://www.djangoproject.com/download/1.7.b4/tarball/" + - DJANGO="https://www.djangoproject.com/download/1.7c2/tarball/" - DJANGO="django==1.6.5" - DJANGO="django==1.5.8" - DJANGO="django==1.4.13" @@ -16,15 +16,13 @@ env: install: - pip install $DJANGO - - pip install defusedxml==0.3 Pillow==2.3.0 + - pip install defusedxml==0.3 Pillow==2.3.0 django-guardian==1.2.3 - "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install oauth2==1.5.211; fi" - "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install django-oauth-plus==2.2.4; fi" - "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install django-oauth2-provider==0.2.4; fi" - - "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install django-guardian==1.1.1; fi" - "if [[ ${DJANGO::11} == 'django==1.3' ]]; then pip install django-filter==0.5.4; fi" - "if [[ ${DJANGO::11} != 'django==1.3' ]]; then pip install django-filter==0.7; fi" - - "if [[ ${TRAVIS_PYTHON_VERSION::1} == '3' ]]; then pip install -e git+https://github.com/linovia/django-guardian.git@feature/django_1_7#egg=django-guardian-1.2.0; fi" - - "if [[ ${DJANGO} == 'https://www.djangoproject.com/download/1.7.b4/tarball/' ]]; then pip install -e git+https://github.com/linovia/django-guardian.git@feature/django_1_7#egg=django-guardian-1.2.0; fi" + - "if [[ ${DJANGO} == 'https://www.djangoproject.com/download/1.7c2/tarball/' ]]; then pip install -e git+https://github.com/linovia/django-guardian.git@feature/django_1_7#egg=django-guardian-1.2.0; fi" - export PYTHONPATH=. script: @@ -33,7 +31,7 @@ script: matrix: exclude: - python: "2.6" - env: DJANGO="https://www.djangoproject.com/download/1.7.b4/tarball/" + env: DJANGO="https://www.djangoproject.com/download/1.7c2/tarball/" - python: "3.2" env: DJANGO="django==1.4.13" - python: "3.2" diff --git a/README.md b/README.md index 73e4b13fc..eea002b4a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ +--- + +#### Django REST framework 3 - Kickstarter announcement! + +We are currently running a Kickstarter campaign to help fund the development of Django REST framework 3. + +If you want to help drive sustainable open-source development forward, then **please check out [the Kickstarter project](https://www.kickstarter.com/projects/tomchristie/django-rest-framework-3) and consider funding us.** + +--- + # Django REST framework [![build-status-image]][travis] @@ -136,6 +146,7 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + [build-status-image]: https://secure.travis-ci.org/tomchristie/django-rest-framework.png?branch=master [travis]: http://travis-ci.org/tomchristie/django-rest-framework?branch=master [twitter]: https://twitter.com/_tomchristie diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index 58dbf977e..dd2795415 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -347,7 +347,7 @@ As an example, let's create a field that can be used represent the class name of """ Serialize the object's class name. """ - return obj.__class__ + return obj.__class__.__name__ # Third party packages @@ -357,9 +357,20 @@ The following third party packages are also available. The [drf-compound-fields][drf-compound-fields] package provides "compound" serializer fields, such as lists of simple values, which can be described by other fields rather than serializers with the `many=True` option. Also provided are fields for typed dictionaries and values that can be either a specific type or a list of items of that type. +## DRF Extra Fields + +The [drf-extra-fields][drf-extra-fields] package provides extra serializer fields for REST framework, including `Base64ImageField` and `PointField` classes. + +## django-rest-framework-gis + +The [django-rest-framework-gis][django-rest-framework-gis] package provides geographic addons for django rest framework like a `GeometryField` field and a GeoJSON serializer. + + [cite]: https://docs.djangoproject.com/en/dev/ref/forms/api/#django.forms.Form.cleaned_data [FILE_UPLOAD_HANDLERS]: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FILE_UPLOAD_HANDLERS [ecma262]: http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.15 [strftime]: http://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior [iso8601]: http://www.w3.org/TR/NOTE-datetime [drf-compound-fields]: http://drf-compound-fields.readthedocs.org +[drf-extra-fields]: https://github.com/Hipo/drf-extra-fields +[django-rest-framework-gis]: https://github.com/djangonauts/django-rest-framework-gis diff --git a/docs/api-guide/filtering.md b/docs/api-guide/filtering.md index 6a8a267b2..ec5ab61fe 100644 --- a/docs/api-guide/filtering.md +++ b/docs/api-guide/filtering.md @@ -199,8 +199,7 @@ This enables us to make queries like: http://example.com/api/products?manufacturer__name=foo -This is nice, but it shows underlying model structure in REST API, which may -be undesired, but you can use: +This is nice, but it exposes the Django's double underscore convention as part of the API. If you instead want to explicitly name the filter argument you can instead explicitly include it on the `FilterSet` class: import django_filters from myapp.models import Product @@ -208,7 +207,6 @@ be undesired, but you can use: from rest_framework import generics class ProductFilter(django_filters.FilterSet): - manufacturer = django_filters.CharFilter(name="manufacturer__name") class Meta: diff --git a/docs/api-guide/permissions.md b/docs/api-guide/permissions.md index 50f669a2d..38ae3d0a9 100644 --- a/docs/api-guide/permissions.md +++ b/docs/api-guide/permissions.md @@ -36,6 +36,12 @@ For example: self.check_object_permissions(self.request, obj) return obj +#### Limitations of object level permissions + +For performance reasons the generic views will not automatically apply object level permissions to each instance in a queryset when returning a list of objects. + +Often when you're using object level permissions you'll also want to [filter the queryset][filtering] appropriately, to ensure that users only have visibility onto instances that they are permitted to view. + ## Setting the permission policy The default permission policy may be set globally, using the `DEFAULT_PERMISSION_CLASSES` setting. For example. @@ -237,7 +243,8 @@ The [REST Condition][rest-condition] package is another extension for building c [cite]: https://developer.apple.com/library/mac/#documentation/security/Conceptual/AuthenticationAndAuthorizationGuide/Authorization/Authorization.html [authentication]: authentication.md [throttling]: throttling.md -[contribauth]: https://docs.djangoproject.com/en/1.0/topics/auth/#permissions +[filtering]: filtering.md +[contribauth]: https://docs.djangoproject.com/en/dev/topics/auth/customizing/#custom-permissions [objectpermissions]: https://docs.djangoproject.com/en/dev/topics/auth/customizing/#handling-object-permissions [guardian]: https://github.com/lukaszb/django-guardian [get_objects_for_user]: http://pythonhosted.org/django-guardian/api/guardian.shortcuts.html#get-objects-for-user diff --git a/docs/api-guide/routers.md b/docs/api-guide/routers.md index 7efc140a5..64f05af39 100644 --- a/docs/api-guide/routers.md +++ b/docs/api-guide/routers.md @@ -179,7 +179,16 @@ The [wq.db package][wq.db] provides an advanced [Router][wq.db-router] class (an app.router.register_model(MyModel) +## DRF-extensions + +The [`DRF-extensions` package][drf-extensions] provides [routers][drf-extensions-routers] for creating [nested viewsets][drf-extensions-nested-viewsets], [collection level controllers][drf-extensions-collection-level-controllers] with [customizable endpoint names][drf-extensions-customizable-endpoint-names]. + [cite]: http://guides.rubyonrails.org/routing.html [drf-nested-routers]: https://github.com/alanjds/drf-nested-routers [wq.db]: http://wq.io/wq.db [wq.db-router]: http://wq.io/docs/app.py +[drf-extensions]: http://chibisov.github.io/drf-extensions/docs/ +[drf-extensions-routers]: http://chibisov.github.io/drf-extensions/docs/#routers +[drf-extensions-nested-viewsets]: http://chibisov.github.io/drf-extensions/docs/#nested-routes +[drf-extensions-collection-level-controllers]: http://chibisov.github.io/drf-extensions/docs/#collection-level-controllers +[drf-extensions-customizable-endpoint-names]: http://chibisov.github.io/drf-extensions/docs/#controller-endpoint-name \ No newline at end of file diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index cedf1ff7b..29b7851b6 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -580,7 +580,21 @@ The following custom model serializer could be used as a base class for model se def get_pk_field(self, model_field): return None +--- +# Third party packages + +The following third party packages are also available. + +## MongoengineModelSerializer + +The [django-rest-framework-mongoengine][mongoengine] package provides a `MongoEngineModelSerializer` serializer class that supports using MongoDB as the storage layer for Django REST framework. + +## GeoFeatureModelSerializer + +The [django-rest-framework-gis][django-rest-framework-gis] package provides a `GeoFeatureModelSerializer` serializer class that supports GeoJSON both for read and write operations. [cite]: https://groups.google.com/d/topic/django-users/sVFaOfQi4wY/discussion [relations]: relations.md +[mongoengine]: https://github.com/umutbozkurt/django-rest-framework-mongoengine +[django-rest-framework-gis]: https://github.com/djangonauts/django-rest-framework-gis diff --git a/docs/api-guide/throttling.md b/docs/api-guide/throttling.md index b7c320f01..92f4c22bb 100644 --- a/docs/api-guide/throttling.md +++ b/docs/api-guide/throttling.md @@ -58,7 +58,7 @@ using the `APIView` class based views. Or, if you're using the `@api_view` decorator with function based views. - @api_view('GET') + @api_view(['GET']) @throttle_classes([UserRateThrottle]) def example_view(request, format=None): content = { diff --git a/docs/css/default.css b/docs/css/default.css index af6a9cc03..7f3acfed2 100644 --- a/docs/css/default.css +++ b/docs/css/default.css @@ -307,3 +307,76 @@ table { .side-nav { overflow-y: scroll; } + + +ul.sponsor.diamond li a { + float: left; + width: 600px; + height: 20px; + text-align: center; + margin: 10px 70px; + padding: 300px 0 0 0; + background-position: 0 50%; + background-size: 600px auto; + background-repeat: no-repeat; + font-size: 200%; +} + +@media (max-width: 1000px) { + ul.sponsor.diamond li a { + float: left; + width: 300px; + height: 20px; + text-align: center; + margin: 10px 40px; + padding: 300px 0 0 0; + background-position: 0 50%; + background-size: 280px auto; + background-repeat: no-repeat; + font-size: 150%; + } +} + +ul.sponsor.platinum li a { + float: left; + width: 300px; + height: 20px; + text-align: center; + margin: 10px 40px; + padding: 300px 0 0 0; + background-position: 0 50%; + background-size: 280px auto; + background-repeat: no-repeat; + font-size: 150%; +} + +ul.sponsor.gold li a { + float: left; + width: 130px; + height: 20px; + text-align: center; + margin: 10px 30px; + padding: 150px 0 0 0; + background-position: 0 50%; + background-size: 130px auto; + background-repeat: no-repeat; + font-size: 120%; +} + +ul.sponsor.silver li a { + float: left; + width: 130px; + height: 20px; + text-align: center; + margin: 10px 30px; + padding: 150px 0 0 0; + background-position: 0 50%; + background-size: 130px auto; + background-repeat: no-repeat; + font-size: 120%; +} + +ul.sponsor { + list-style: none; + display: block; +} diff --git a/docs/img/sponsors/0-eventbrite.png b/docs/img/sponsors/0-eventbrite.png new file mode 100644 index 000000000..6c7392936 Binary files /dev/null and b/docs/img/sponsors/0-eventbrite.png differ diff --git a/docs/img/sponsors/1-cyan.png b/docs/img/sponsors/1-cyan.png new file mode 100644 index 000000000..d6b55b4c5 Binary files /dev/null and b/docs/img/sponsors/1-cyan.png differ diff --git a/docs/img/sponsors/1-divio.png b/docs/img/sponsors/1-divio.png new file mode 100644 index 000000000..8ced88f82 Binary files /dev/null and b/docs/img/sponsors/1-divio.png differ diff --git a/docs/img/sponsors/1-kuwaitnet.png b/docs/img/sponsors/1-kuwaitnet.png new file mode 100644 index 000000000..8b2d0550a Binary files /dev/null and b/docs/img/sponsors/1-kuwaitnet.png differ diff --git a/docs/img/sponsors/1-lulu.png b/docs/img/sponsors/1-lulu.png new file mode 100644 index 000000000..8a28bfa9f Binary files /dev/null and b/docs/img/sponsors/1-lulu.png differ diff --git a/docs/img/sponsors/1-potato.png b/docs/img/sponsors/1-potato.png new file mode 100644 index 000000000..ad38abdd2 Binary files /dev/null and b/docs/img/sponsors/1-potato.png differ diff --git a/docs/img/sponsors/1-purplebit.png b/docs/img/sponsors/1-purplebit.png new file mode 100644 index 000000000..0df63bf60 Binary files /dev/null and b/docs/img/sponsors/1-purplebit.png differ diff --git a/docs/img/sponsors/1-runscope.png b/docs/img/sponsors/1-runscope.png new file mode 100644 index 000000000..d80a4b85b Binary files /dev/null and b/docs/img/sponsors/1-runscope.png differ diff --git a/docs/img/sponsors/1-simple-energy.png b/docs/img/sponsors/1-simple-energy.png new file mode 100644 index 000000000..f59f7374c Binary files /dev/null and b/docs/img/sponsors/1-simple-energy.png differ diff --git a/docs/img/sponsors/1-vokal_interactive.png b/docs/img/sponsors/1-vokal_interactive.png new file mode 100644 index 000000000..431482dca Binary files /dev/null and b/docs/img/sponsors/1-vokal_interactive.png differ diff --git a/docs/img/sponsors/1-wiredrive.png b/docs/img/sponsors/1-wiredrive.png new file mode 100644 index 000000000..c9befefe4 Binary files /dev/null and b/docs/img/sponsors/1-wiredrive.png differ diff --git a/docs/img/sponsors/2-byte.png b/docs/img/sponsors/2-byte.png new file mode 100644 index 000000000..2c3777b50 Binary files /dev/null and b/docs/img/sponsors/2-byte.png differ diff --git a/docs/img/sponsors/2-crate.png b/docs/img/sponsors/2-crate.png new file mode 100644 index 000000000..6ef6b5da5 Binary files /dev/null and b/docs/img/sponsors/2-crate.png differ diff --git a/docs/img/sponsors/2-cryptico.png b/docs/img/sponsors/2-cryptico.png new file mode 100644 index 000000000..2d86afe81 Binary files /dev/null and b/docs/img/sponsors/2-cryptico.png differ diff --git a/docs/img/sponsors/2-django.png b/docs/img/sponsors/2-django.png new file mode 100644 index 000000000..c89e19cb3 Binary files /dev/null and b/docs/img/sponsors/2-django.png differ diff --git a/docs/img/sponsors/2-galileo_press.png b/docs/img/sponsors/2-galileo_press.png new file mode 100644 index 000000000..f77e6c0a8 Binary files /dev/null and b/docs/img/sponsors/2-galileo_press.png differ diff --git a/docs/img/sponsors/2-heroku.png b/docs/img/sponsors/2-heroku.png new file mode 100644 index 000000000..224476596 Binary files /dev/null and b/docs/img/sponsors/2-heroku.png differ diff --git a/docs/img/sponsors/2-hipflask.png b/docs/img/sponsors/2-hipflask.png new file mode 100644 index 000000000..c74735c34 Binary files /dev/null and b/docs/img/sponsors/2-hipflask.png differ diff --git a/docs/img/sponsors/2-hipo.png b/docs/img/sponsors/2-hipo.png new file mode 100644 index 000000000..2b854c6d4 Binary files /dev/null and b/docs/img/sponsors/2-hipo.png differ diff --git a/docs/img/sponsors/2-koordinates.png b/docs/img/sponsors/2-koordinates.png new file mode 100644 index 000000000..f38601b34 Binary files /dev/null and b/docs/img/sponsors/2-koordinates.png differ diff --git a/docs/img/sponsors/2-laterpay.png b/docs/img/sponsors/2-laterpay.png new file mode 100644 index 000000000..75eb97d3f Binary files /dev/null and b/docs/img/sponsors/2-laterpay.png differ diff --git a/docs/img/sponsors/2-lightning_kite.png b/docs/img/sponsors/2-lightning_kite.png new file mode 100644 index 000000000..ffdced04e Binary files /dev/null and b/docs/img/sponsors/2-lightning_kite.png differ diff --git a/docs/img/sponsors/2-mirus_research.png b/docs/img/sponsors/2-mirus_research.png new file mode 100644 index 000000000..b15440708 Binary files /dev/null and b/docs/img/sponsors/2-mirus_research.png differ diff --git a/docs/img/sponsors/2-opbeat.png b/docs/img/sponsors/2-opbeat.png new file mode 100644 index 000000000..c71a52417 Binary files /dev/null and b/docs/img/sponsors/2-opbeat.png differ diff --git a/docs/img/sponsors/2-prorenata.png b/docs/img/sponsors/2-prorenata.png new file mode 100644 index 000000000..f5e8bb762 Binary files /dev/null and b/docs/img/sponsors/2-prorenata.png differ diff --git a/docs/img/sponsors/2-rapasso.png b/docs/img/sponsors/2-rapasso.png new file mode 100644 index 000000000..618e294be Binary files /dev/null and b/docs/img/sponsors/2-rapasso.png differ diff --git a/docs/img/sponsors/2-schuberg_philis.png b/docs/img/sponsors/2-schuberg_philis.png new file mode 100644 index 000000000..fd9282eeb Binary files /dev/null and b/docs/img/sponsors/2-schuberg_philis.png differ diff --git a/docs/img/sponsors/2-security_compass.png b/docs/img/sponsors/2-security_compass.png new file mode 100644 index 000000000..abd63dbe3 Binary files /dev/null and b/docs/img/sponsors/2-security_compass.png differ diff --git a/docs/img/sponsors/2-sga.png b/docs/img/sponsors/2-sga.png new file mode 100644 index 000000000..2b2a3b3bb Binary files /dev/null and b/docs/img/sponsors/2-sga.png differ diff --git a/docs/img/sponsors/2-sirono.png b/docs/img/sponsors/2-sirono.png new file mode 100644 index 000000000..0a243001a Binary files /dev/null and b/docs/img/sponsors/2-sirono.png differ diff --git a/docs/img/sponsors/2-vinta.png b/docs/img/sponsors/2-vinta.png new file mode 100644 index 000000000..4f4d75bc1 Binary files /dev/null and b/docs/img/sponsors/2-vinta.png differ diff --git a/docs/img/sponsors/3-aba.png b/docs/img/sponsors/3-aba.png new file mode 100644 index 000000000..cefa3dd60 Binary files /dev/null and b/docs/img/sponsors/3-aba.png differ diff --git a/docs/img/sponsors/3-aditium.png b/docs/img/sponsors/3-aditium.png new file mode 100644 index 000000000..0952b08c8 Binary files /dev/null and b/docs/img/sponsors/3-aditium.png differ diff --git a/docs/img/sponsors/3-alwaysdata.png b/docs/img/sponsors/3-alwaysdata.png new file mode 100644 index 000000000..4095774b7 Binary files /dev/null and b/docs/img/sponsors/3-alwaysdata.png differ diff --git a/docs/img/sponsors/3-beefarm.png b/docs/img/sponsors/3-beefarm.png new file mode 100644 index 000000000..3348df42a Binary files /dev/null and b/docs/img/sponsors/3-beefarm.png differ diff --git a/docs/img/sponsors/3-blimp.png b/docs/img/sponsors/3-blimp.png new file mode 100644 index 000000000..494bf7924 Binary files /dev/null and b/docs/img/sponsors/3-blimp.png differ diff --git a/docs/img/sponsors/3-brightloop.png b/docs/img/sponsors/3-brightloop.png new file mode 100644 index 000000000..8d5e85a66 Binary files /dev/null and b/docs/img/sponsors/3-brightloop.png differ diff --git a/docs/img/sponsors/3-fluxility.png b/docs/img/sponsors/3-fluxility.png new file mode 100644 index 000000000..eacd7da97 Binary files /dev/null and b/docs/img/sponsors/3-fluxility.png differ diff --git a/docs/img/sponsors/3-garfo.png b/docs/img/sponsors/3-garfo.png new file mode 100644 index 000000000..a9bdea0a0 Binary files /dev/null and b/docs/img/sponsors/3-garfo.png differ diff --git a/docs/img/sponsors/3-gizmag.png b/docs/img/sponsors/3-gizmag.png new file mode 100644 index 000000000..a8d41bd02 Binary files /dev/null and b/docs/img/sponsors/3-gizmag.png differ diff --git a/docs/img/sponsors/3-imt_computer_services.png b/docs/img/sponsors/3-imt_computer_services.png new file mode 100644 index 000000000..00643c978 Binary files /dev/null and b/docs/img/sponsors/3-imt_computer_services.png differ diff --git a/docs/img/sponsors/3-infinite_code.png b/docs/img/sponsors/3-infinite_code.png new file mode 100644 index 000000000..7a8fdcf16 Binary files /dev/null and b/docs/img/sponsors/3-infinite_code.png differ diff --git a/docs/img/sponsors/3-life_the_game.png b/docs/img/sponsors/3-life_the_game.png new file mode 100644 index 000000000..9292685e7 Binary files /dev/null and b/docs/img/sponsors/3-life_the_game.png differ diff --git a/docs/img/sponsors/3-nephila.png b/docs/img/sponsors/3-nephila.png new file mode 100644 index 000000000..a905fa938 Binary files /dev/null and b/docs/img/sponsors/3-nephila.png differ diff --git a/docs/img/sponsors/3-pathwright.png b/docs/img/sponsors/3-pathwright.png new file mode 100644 index 000000000..71be3b28b Binary files /dev/null and b/docs/img/sponsors/3-pathwright.png differ diff --git a/docs/img/sponsors/3-pkgfarm.png b/docs/img/sponsors/3-pkgfarm.png new file mode 100644 index 000000000..9224cc2ee Binary files /dev/null and b/docs/img/sponsors/3-pkgfarm.png differ diff --git a/docs/img/sponsors/3-providenz.png b/docs/img/sponsors/3-providenz.png new file mode 100644 index 000000000..55d9c992a Binary files /dev/null and b/docs/img/sponsors/3-providenz.png differ diff --git a/docs/img/sponsors/3-safari.png b/docs/img/sponsors/3-safari.png new file mode 100644 index 000000000..c03e40e84 Binary files /dev/null and b/docs/img/sponsors/3-safari.png differ diff --git a/docs/img/sponsors/3-shippo.png b/docs/img/sponsors/3-shippo.png new file mode 100644 index 000000000..4f5ae133a Binary files /dev/null and b/docs/img/sponsors/3-shippo.png differ diff --git a/docs/img/sponsors/3-thermondo-gmbh.png b/docs/img/sponsors/3-thermondo-gmbh.png new file mode 100644 index 000000000..fe8691c8d Binary files /dev/null and b/docs/img/sponsors/3-thermondo-gmbh.png differ diff --git a/docs/img/sponsors/3-tivix.png b/docs/img/sponsors/3-tivix.png new file mode 100644 index 000000000..bc2616a62 Binary files /dev/null and b/docs/img/sponsors/3-tivix.png differ diff --git a/docs/img/sponsors/3-trackmaven.png b/docs/img/sponsors/3-trackmaven.png new file mode 100644 index 000000000..3880e3707 Binary files /dev/null and b/docs/img/sponsors/3-trackmaven.png differ diff --git a/docs/img/sponsors/3-triggered_messaging.png b/docs/img/sponsors/3-triggered_messaging.png new file mode 100644 index 000000000..4f8e50635 Binary files /dev/null and b/docs/img/sponsors/3-triggered_messaging.png differ diff --git a/docs/img/sponsors/3-vzzual.png b/docs/img/sponsors/3-vzzual.png new file mode 100644 index 000000000..98edce028 Binary files /dev/null and b/docs/img/sponsors/3-vzzual.png differ diff --git a/docs/img/sponsors/3-wildfish.png b/docs/img/sponsors/3-wildfish.png new file mode 100644 index 000000000..fa13ea703 Binary files /dev/null and b/docs/img/sponsors/3-wildfish.png differ diff --git a/docs/index.md b/docs/index.md index 2a4ad8859..d9c686c4a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -9,6 +9,14 @@ --- +#### Django REST framework 3 - Kickstarter announcement! + +We are currently running a Kickstarter campaign to help fund the development of Django REST framework 3. + +If you want to help drive sustainable open-source development **please [check out the Kickstarter project](https://www.kickstarter.com/projects/tomchristie/django-rest-framework-3) and consider funding us.** + +--- +

@@ -106,6 +121,7 @@
  • 2.0 Announcement
  • 2.2 Announcement
  • 2.3 Announcement
  • +
  • Kickstarter Announcement
  • Release Notes
  • Credits
  • @@ -169,11 +185,9 @@
    @@ -199,6 +213,7 @@ + """) else: output = output.replace('{{ ad_block }}', '') diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index da9ca510e..887ef5d73 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -310,6 +310,13 @@ class OAuth2Authentication(BaseAuthentication): auth = get_authorization_header(request).split() + if len(auth) == 1: + msg = 'Invalid bearer header. No credentials provided.' + raise exceptions.AuthenticationFailed(msg) + elif len(auth) > 2: + msg = 'Invalid bearer header. Token string should not contain spaces.' + raise exceptions.AuthenticationFailed(msg) + if auth and auth[0].lower() == b'bearer': access_token = auth[1] elif 'access_token' in request.POST: @@ -319,13 +326,6 @@ class OAuth2Authentication(BaseAuthentication): else: return None - if len(auth) == 1: - msg = 'Invalid bearer header. No credentials provided.' - raise exceptions.AuthenticationFailed(msg) - elif len(auth) > 2: - msg = 'Invalid bearer header. Token string should not contain spaces.' - raise exceptions.AuthenticationFailed(msg) - return self.authenticate_credentials(request, access_token) def authenticate_credentials(self, request, access_token): diff --git a/rest_framework/compat.py b/rest_framework/compat.py index fdf12448a..9ad8b0d28 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -48,12 +48,15 @@ try: except ImportError: django_filters = None -# guardian is optional -try: - import guardian - import guardian.shortcuts # Fixes #1624 -except ImportError: - guardian = None +# Django-guardian is optional. Import only if guardian is in INSTALLED_APPS +# Fixes (#1712). We keep the try/except for the test suite. +guardian = None +if 'guardian' in settings.INSTALLED_APPS: + try: + import guardian + import guardian.shortcuts # Fixes #1624 + except ImportError: + pass # cStringIO only if it's available, otherwise StringIO diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 86e8fd9df..6caae9242 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -187,7 +187,7 @@ class Field(object): def field_to_native(self, obj, field_name): """ - Given and object and a field name, returns the value that should be + Given an object and a field name, returns the value that should be serialized for that field. """ if obj is None: @@ -474,8 +474,12 @@ class CharField(WritableField): self.validators.append(validators.MaxLengthValidator(max_length)) def from_native(self, value): - if isinstance(value, six.string_types) or value is None: + if isinstance(value, six.string_types): return value + + if value is None: + return '' + return smart_text(value) diff --git a/rest_framework/filters.py b/rest_framework/filters.py index 96d15eb9d..c3b846aed 100644 --- a/rest_framework/filters.py +++ b/rest_framework/filters.py @@ -116,6 +116,10 @@ class OrderingFilter(BaseFilterBackend): def get_ordering(self, request): """ Ordering is set by a comma delimited ?ordering=... query parameter. + + The `ordering` query parameter can be overridden by setting + the `ordering_param` value on the OrderingFilter or by + specifying an `ORDERING_PARAM` value in the API settings. """ params = request.QUERY_PARAMS.get(self.ordering_param) if params: diff --git a/rest_framework/response.py b/rest_framework/response.py index 1dc6abcf6..5c02ea508 100644 --- a/rest_framework/response.py +++ b/rest_framework/response.py @@ -5,6 +5,7 @@ it is initialized with unrendered data, instead of a pre-rendered string. The appropriate renderer is called during Django's template response rendering. """ from __future__ import unicode_literals +import django from django.core.handlers.wsgi import STATUS_CODE_TEXT from django.template.response import SimpleTemplateResponse from rest_framework.compat import six @@ -15,6 +16,9 @@ class Response(SimpleTemplateResponse): An HttpResponse that allows its data to be rendered into arbitrary media types. """ + # TODO: remove that once Django 1.3 isn't supported + if django.VERSION >= (1, 4): + rendering_attrs = SimpleTemplateResponse.rendering_attrs + ['_closable_objects'] def __init__(self, data=None, status=200, template_name=None, headers=None, diff --git a/rest_framework/templates/rest_framework/base.html b/rest_framework/templates/rest_framework/base.html index 7067ee2f0..e96fa8ec5 100644 --- a/rest_framework/templates/rest_framework/base.html +++ b/rest_framework/templates/rest_framework/base.html @@ -93,7 +93,7 @@ {% endif %} {% if options_form %} -
    + {% csrf_token %} @@ -101,7 +101,7 @@ {% endif %} {% if delete_form %} - + {% csrf_token %} diff --git a/rest_framework/tests/models.py b/rest_framework/tests/models.py index e171d3bd9..fba3f8f7c 100644 --- a/rest_framework/tests/models.py +++ b/rest_framework/tests/models.py @@ -105,6 +105,7 @@ class Album(RESTFrameworkModel): title = models.CharField(max_length=100, unique=True) ref = models.CharField(max_length=10, unique=True, null=True, blank=True) + class Photo(RESTFrameworkModel): description = models.TextField() album = models.ForeignKey(Album) @@ -112,7 +113,8 @@ class Photo(RESTFrameworkModel): # Model for issue #324 class BlankFieldModel(RESTFrameworkModel): - title = models.CharField(max_length=100, blank=True, null=False) + title = models.CharField(max_length=100, blank=True, null=False, + default="title") # Model for issue #380 diff --git a/rest_framework/tests/test_authentication.py b/rest_framework/tests/test_authentication.py index a1c43d9ce..34bf29101 100644 --- a/rest_framework/tests/test_authentication.py +++ b/rest_framework/tests/test_authentication.py @@ -549,6 +549,15 @@ class OAuth2Tests(TestCase): response = self.csrf_client.get('/oauth2-test/', HTTP_AUTHORIZATION=auth) self.assertEqual(response.status_code, 401) + @unittest.skipUnless(oauth2_provider, 'django-oauth2-provider not installed') + def test_get_form_with_wrong_authorization_header_token_missing(self): + """Ensure that a missing token lead to the correct HTTP error status code""" + auth = "Bearer" + response = self.csrf_client.get('/oauth2-test/', {}, HTTP_AUTHORIZATION=auth) + self.assertEqual(response.status_code, 401) + response = self.csrf_client.get('/oauth2-test/', HTTP_AUTHORIZATION=auth) + self.assertEqual(response.status_code, 401) + @unittest.skipUnless(oauth2_provider, 'django-oauth2-provider not installed') def test_get_form_passing_auth(self): """Ensure GETing form over OAuth with correct client credentials succeed""" diff --git a/rest_framework/tests/test_serializer.py b/rest_framework/tests/test_serializer.py index e688c8239..91248ce7c 100644 --- a/rest_framework/tests/test_serializer.py +++ b/rest_framework/tests/test_serializer.py @@ -1236,6 +1236,9 @@ class BlankFieldTests(TestCase): def test_create_model_null_field(self): serializer = self.model_serializer_class(data={'title': None}) self.assertEqual(serializer.is_valid(), True) + serializer.save() + self.assertIsNot(serializer.object.pk, None) + self.assertEqual(serializer.object.title, '') def test_create_not_blank_field(self): """ diff --git a/tox.ini b/tox.ini index 279f79cc4..72d156f9b 100644 --- a/tox.ini +++ b/tox.ini @@ -12,34 +12,34 @@ commands = {envpython} rest_framework/runtests/runtests.py [testenv:py3.4-django1.7] basepython = python3.4 -deps = https://www.djangoproject.com/download/1.7b2/tarball/ +deps = https://www.djangoproject.com/download/1.7c2/tarball/ django-filter==0.7 defusedxml==0.3 Pillow==2.3.0 [testenv:py3.3-django1.7] basepython = python3.3 -deps = https://www.djangoproject.com/download/1.7b2/tarball/ +deps = https://www.djangoproject.com/download/1.7c2/tarball/ django-filter==0.7 defusedxml==0.3 Pillow==2.3.0 [testenv:py3.2-django1.7] basepython = python3.2 -deps = https://www.djangoproject.com/download/1.7b2/tarball/ +deps = https://www.djangoproject.com/download/1.7c2/tarball/ django-filter==0.7 defusedxml==0.3 Pillow==2.3.0 [testenv:py2.7-django1.7] basepython = python2.7 -deps = https://www.djangoproject.com/download/1.7b2/tarball/ +deps = https://www.djangoproject.com/download/1.7c2/tarball/ django-filter==0.7 defusedxml==0.3 - django-oauth-plus==2.2.1 - oauth2==1.5.211 - django-oauth2-provider==0.2.4 - django-guardian==1.1.1 + # django-oauth-plus==2.2.1 + # oauth2==1.5.211 + # django-oauth2-provider==0.2.4 + django-guardian==1.2.3 Pillow==2.3.0 [testenv:py3.4-django1.6] @@ -71,7 +71,7 @@ deps = Django==1.6.3 django-oauth-plus==2.2.1 oauth2==1.5.211 django-oauth2-provider==0.2.4 - django-guardian==1.1.1 + django-guardian==1.2.3 Pillow==2.3.0 [testenv:py2.6-django1.6] @@ -82,7 +82,7 @@ deps = Django==1.6.3 django-oauth-plus==2.2.1 oauth2==1.5.211 django-oauth2-provider==0.2.4 - django-guardian==1.1.1 + django-guardian==1.2.3 Pillow==2.3.0 [testenv:py3.4-django1.5] @@ -114,7 +114,7 @@ deps = django==1.5.6 django-oauth-plus==2.2.1 oauth2==1.5.211 django-oauth2-provider==0.2.3 - django-guardian==1.1.1 + django-guardian==1.2.3 Pillow==2.3.0 [testenv:py2.6-django1.5] @@ -125,7 +125,7 @@ deps = django==1.5.6 django-oauth-plus==2.2.1 oauth2==1.5.211 django-oauth2-provider==0.2.3 - django-guardian==1.1.1 + django-guardian==1.2.3 Pillow==2.3.0 [testenv:py2.7-django1.4] @@ -136,7 +136,7 @@ deps = django==1.4.11 django-oauth-plus==2.2.1 oauth2==1.5.211 django-oauth2-provider==0.2.3 - django-guardian==1.1.1 + django-guardian==1.2.3 Pillow==2.3.0 [testenv:py2.6-django1.4] @@ -147,7 +147,7 @@ deps = django==1.4.11 django-oauth-plus==2.2.1 oauth2==1.5.211 django-oauth2-provider==0.2.3 - django-guardian==1.1.1 + django-guardian==1.2.3 Pillow==2.3.0 [testenv:py2.7-django1.3] @@ -158,7 +158,7 @@ deps = django==1.3.5 django-oauth-plus==2.2.1 oauth2==1.5.211 django-oauth2-provider==0.2.3 - django-guardian==1.1.1 + django-guardian==1.2.3 Pillow==2.3.0 [testenv:py2.6-django1.3] @@ -169,5 +169,5 @@ deps = django==1.3.5 django-oauth-plus==2.2.1 oauth2==1.5.211 django-oauth2-provider==0.2.3 - django-guardian==1.1.1 + django-guardian==1.2.3 Pillow==2.3.0