From 3e44f788b194e74777013841d18a2a035df0757d Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Mon, 9 Mar 2015 17:28:00 +0100 Subject: Fixed a typo in the documentation's link. --- docs/topics/3.1-announcement.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/topics/3.1-announcement.md b/docs/topics/3.1-announcement.md index 6eb3681f..80d4007e 100644 --- a/docs/topics/3.1-announcement.md +++ b/docs/topics/3.1-announcement.md @@ -206,4 +206,4 @@ This will either be made as a single 3.2 release, or split across two separate r [pagination]: ../api-guide/pagination.md [versioning]: ../api-guide/versioning.md [internationalization]: internationalization.md -[customizing-field-mappings]: ../api-guide/serializers.md/#customizing-field-mappings +[customizing-field-mappings]: ../api-guide/serializers.md#customizing-field-mappings -- cgit v1.2.3 From 69b6e26f06c787761bb8d6006ed6fc607fbc9d23 Mon Sep 17 00:00:00 2001 From: Bryan Alsdorf Date: Tue, 10 Mar 2015 17:30:41 -0500 Subject: Changed incorrect class name --- docs/api-guide/pagination.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api-guide/pagination.md b/docs/api-guide/pagination.md index 3518fb34..eca468b8 100644 --- a/docs/api-guide/pagination.md +++ b/docs/api-guide/pagination.md @@ -127,7 +127,7 @@ This pagination style mirrors the syntax used when looking up multiple database #### Setup -To enable the `PageNumberPagination` style globally, use the following configuration: +To enable the `LimitOffsetPagination` style globally, use the following configuration: REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination' -- cgit v1.2.3 From 7854c939dd077b54c8bcecb649581e2a9fd6399f Mon Sep 17 00:00:00 2001 From: James Rutherford Date: Wed, 11 Mar 2015 10:44:42 +0000 Subject: Fixed import statement in API docs --- docs/api-guide/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api-guide/testing.md b/docs/api-guide/testing.md index 8a848c20..dd3295c4 100644 --- a/docs/api-guide/testing.md +++ b/docs/api-guide/testing.md @@ -65,7 +65,7 @@ When testing views directly using a request factory, it's often convenient to be To forcibly authenticate a request, use the `force_authenticate()` method. - from rest_framework.tests import force_authenticate + from rest_framework.test import force_authenticate factory = APIRequestFactory() user = User.objects.get(username='olivia') -- cgit v1.2.3 From 2484dbf4e15e2156079b4bcd447b17258649e67f Mon Sep 17 00:00:00 2001 From: Esmail Date: Wed, 11 Mar 2015 12:00:19 -0400 Subject: Fix example of explicit format URL (for real). Do what I meant to do in #2670: The link is displayed in the tutorial as "http://example.com/api/items/4.json" but the hyperlink itself and what the example code actually works with are (in my opinion, less pretty) URLs like "http://example.com/api/items/4/.json".--- docs/tutorial/2-requests-and-responses.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorial/2-requests-and-responses.md b/docs/tutorial/2-requests-and-responses.md index e2c173d6..2cad1e5d 100644 --- a/docs/tutorial/2-requests-and-responses.md +++ b/docs/tutorial/2-requests-and-responses.md @@ -200,7 +200,7 @@ See the [browsable api][browsable-api] topic for more information about the brow In [tutorial part 3][tut-3], we'll start using class based views, and see how generic views reduce the amount of code we need to write. -[json-url]: http://example.com/api/items/4.json +[json-url]: http://example.com/api/items/4/.json [devserver]: http://127.0.0.1:8000/snippets/ [browsable-api]: ../topics/browsable-api.md [tut-1]: 1-serialization.md -- cgit v1.2.3 From 6c1d0d7ed05941c7a673d1bb3f0e1b56a4b6ab44 Mon Sep 17 00:00:00 2001 From: Dirk Moors Date: Thu, 12 Mar 2015 16:36:26 +0100 Subject: Fixed problem with imporing rest_framework.views in apps.py --- rest_framework/pagination.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index f41a9ae1..5e60448d 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -10,7 +10,7 @@ from django.core.paginator import InvalidPage, Paginator as DjangoPaginator from django.template import Context, loader from django.utils import six from django.utils.six.moves.urllib import parse as urlparse -from django.utils.translation import ugettext as _ +from django.utils.translation import ugettext_lazy as _ from rest_framework.compat import OrderedDict from rest_framework.exceptions import NotFound from rest_framework.response import Response -- cgit v1.2.3 From a02098b855aad0847cddacc4bed2d280017b46c5 Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Fri, 13 Mar 2015 00:15:53 +0100 Subject: Fix the link to the old doc (#2681). --- docs/topics/release-notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md index 35592feb..84d310c2 100644 --- a/docs/topics/release-notes.md +++ b/docs/topics/release-notes.md @@ -154,7 +154,7 @@ For older release notes, [please see the version 2.x documentation](old-release- [2.1.0-notes]: https://groups.google.com/d/topic/django-rest-framework/Vv2M0CMY9bg/discussion [ticket-582]: https://github.com/tomchristie/django-rest-framework/issues/582 [rfc-6266]: http://tools.ietf.org/html/rfc6266#section-4.3 -[old-release-notes]: http://tomchristie.github.io/rest-framework-2-docs/topics/release-notes#24x-series +[old-release-notes]: https://github.com/tomchristie/django-rest-framework/blob/version-2.4.x/docs/topics/release-notes.md [3.0.1-milestone]: https://github.com/tomchristie/django-rest-framework/issues?q=milestone%3A%223.0.1+Release%22 [3.0.2-milestone]: https://github.com/tomchristie/django-rest-framework/issues?q=milestone%3A%223.0.2+Release%22 -- cgit v1.2.3 From 8d0dbc8092a754e1f0f7d80d93506072556f35a2 Mon Sep 17 00:00:00 2001 From: Raphaël Barrois Date: Fri, 13 Mar 2015 01:07:20 +0100 Subject: Fix lookup_url_kwarg handling in viewsets. The ``lookup_url_kwarg`` is intended to set the name of a field in the URL regexps when using custom ``lookup_field``, but the routers ignore it altogether. --- rest_framework/routers.py | 5 +++-- tests/test_routers.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/rest_framework/routers.py b/rest_framework/routers.py index b1e39ff7..4df852bf 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -218,14 +218,15 @@ class SimpleRouter(BaseRouter): https://github.com/alanjds/drf-nested-routers """ - base_regex = '(?P<{lookup_prefix}{lookup_field}>{lookup_value})' + base_regex = '(?P<{lookup_prefix}{lookup_url_kwarg}>{lookup_value})' # Use `pk` as default field, unset set. Default regex should not # consume `.json` style suffixes and should break at '/' boundaries. lookup_field = getattr(viewset, 'lookup_field', 'pk') + lookup_url_kwarg = getattr(viewset, 'lookup_url_kwarg', None) or lookup_field lookup_value = getattr(viewset, 'lookup_value_regex', '[^/.]+') return base_regex.format( lookup_prefix=lookup_prefix, - lookup_field=lookup_field, + lookup_url_kwarg=lookup_url_kwarg, lookup_value=lookup_value ) diff --git a/tests/test_routers.py b/tests/test_routers.py index 08c58ec7..19eeb868 100644 --- a/tests/test_routers.py +++ b/tests/test_routers.py @@ -32,6 +32,13 @@ class NoteViewSet(viewsets.ModelViewSet): lookup_field = 'uuid' +class KWargedNoteViewSet(viewsets.ModelViewSet): + queryset = RouterTestModel.objects.all() + serializer_class = NoteSerializer + lookup_field = 'text__contains' + lookup_url_kwarg = 'text' + + class MockViewSet(viewsets.ModelViewSet): queryset = None serializer_class = None @@ -40,6 +47,9 @@ class MockViewSet(viewsets.ModelViewSet): notes_router = SimpleRouter() notes_router.register(r'notes', NoteViewSet) +kwarged_notes_router = SimpleRouter() +kwarged_notes_router.register(r'notes', KWargedNoteViewSet) + namespaced_router = DefaultRouter() namespaced_router.register(r'example', MockViewSet, base_name='example') @@ -47,6 +57,7 @@ urlpatterns = [ url(r'^non-namespaced/', include(namespaced_router.urls)), url(r'^namespaced/', include(namespaced_router.urls, namespace='example')), url(r'^example/', include(notes_router.urls)), + url(r'^example2/', include(kwarged_notes_router.urls)), ] @@ -177,6 +188,33 @@ class TestLookupValueRegex(TestCase): self.assertEqual(expected[idx], self.urls[idx].regex.pattern) +class TestLookupUrlKwargs(TestCase): + """ + Ensure the router honors lookup_url_kwarg. + + Setup a deep lookup_field, but map it to a simple URL kwarg. + """ + urls = 'tests.test_routers' + + def setUp(self): + RouterTestModel.objects.create(uuid='123', text='foo bar') + + def test_custom_lookup_url_kwarg_route(self): + detail_route = kwarged_notes_router.urls[-1] + detail_url_pattern = detail_route.regex.pattern + self.assertIn('^notes/(?P', detail_url_pattern) + + def test_retrieve_lookup_url_kwarg_detail_view(self): + response = self.client.get('/example2/notes/fo/') + self.assertEqual( + response.data, + { + "url": "http://testserver/example/notes/123/", + "uuid": "123", "text": "foo bar" + } + ) + + class TestTrailingSlashIncluded(TestCase): def setUp(self): class NoteViewSet(viewsets.ModelViewSet): -- cgit v1.2.3 From 2266fec99dd10984e31ac4b50b9d6fed1355565b Mon Sep 17 00:00:00 2001 From: mochawich Date: Fri, 13 Mar 2015 17:03:51 +0100 Subject: fixed missing anchor closing tag when next_url is none, big part of page html will be rendered under the as it does not have a closing tag.--- .../templates/rest_framework/pagination/previous_and_next.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/templates/rest_framework/pagination/previous_and_next.html b/rest_framework/templates/rest_framework/pagination/previous_and_next.html index eacbfff4..08c17709 100644 --- a/rest_framework/templates/rest_framework/pagination/previous_and_next.html +++ b/rest_framework/templates/rest_framework/pagination/previous_and_next.html @@ -7,6 +7,6 @@ {% if next_url %} {% else %} - + {% endif %} -- cgit v1.2.3 From 76ede5beda74c1bb224f038d635ab586416bfca8 Mon Sep 17 00:00:00 2001 From: José Padilla Date: Sat, 14 Mar 2015 15:54:11 -0400 Subject: Simplify test settings --- tests/conftest.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 44ed070b..03b4e328 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,7 +18,6 @@ def pytest_configure(): MIDDLEWARE_CLASSES=( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ), @@ -27,7 +26,6 @@ def pytest_configure(): 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', - 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', @@ -35,12 +33,7 @@ def pytest_configure(): 'tests', ), PASSWORD_HASHERS=( - 'django.contrib.auth.hashers.SHA1PasswordHasher', - 'django.contrib.auth.hashers.PBKDF2PasswordHasher', - 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', - 'django.contrib.auth.hashers.BCryptPasswordHasher', 'django.contrib.auth.hashers.MD5PasswordHasher', - 'django.contrib.auth.hashers.CryptPasswordHasher', ), ) -- cgit v1.2.3