Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
4cd49d5d
Commit
4cd49d5d
authored
Mar 16, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/tomchristie/django-rest-framework
parents
c573e7b4
1c0db6dd
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
48 additions
and
16 deletions
+48
-16
docs/api-guide/pagination.md
+1
-1
docs/api-guide/testing.md
+1
-1
docs/topics/3.1-announcement.md
+1
-1
docs/topics/release-notes.md
+1
-1
docs/tutorial/2-requests-and-responses.md
+1
-1
rest_framework/pagination.py
+1
-1
rest_framework/routers.py
+3
-2
rest_framework/templates/rest_framework/pagination/previous_and_next.html
+1
-1
tests/conftest.py
+0
-7
tests/test_routers.py
+38
-0
No files found.
docs/api-guide/pagination.md
View file @
4cd49d5d
...
...
@@ -127,7 +127,7 @@ This pagination style mirrors the syntax used when looking up multiple database
#### Setup
To enable the
`
PageNumber
Pagination`
style globally, use the following configuration:
To enable the
`
LimitOffset
Pagination`
style globally, use the following configuration:
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination'
...
...
docs/api-guide/testing.md
View file @
4cd49d5d
...
...
@@ -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.test
s
import force_authenticate
from rest_framework.test import force_authenticate
factory = APIRequestFactory()
user = User.objects.get(username='olivia')
...
...
docs/topics/3.1-announcement.md
View file @
4cd49d5d
...
...
@@ -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
docs/topics/release-notes.md
View file @
4cd49d5d
...
...
@@ -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
]:
http
s://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
...
...
docs/tutorial/2-requests-and-responses.md
View file @
4cd49d5d
...
...
@@ -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
...
...
rest_framework/pagination.py
View file @
4cd49d5d
...
...
@@ -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
...
...
rest_framework/routers.py
View file @
4cd49d5d
...
...
@@ -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
)
...
...
rest_framework/templates/rest_framework/pagination/previous_and_next.html
View file @
4cd49d5d
...
...
@@ -7,6 +7,6 @@
{% if next_url %}
<li
class=
"next"
><a
href=
"{{ next_url }}"
>
Next
»
</a></li>
{% else %}
<li
class=
"next disabled"
><a
href=
"#"
>
Next
»
</li>
<li
class=
"next disabled"
><a
href=
"#"
>
Next
»
</
a></
li>
{% endif %}
</ul>
tests/conftest.py
View file @
4cd49d5d
...
...
@@ -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'
,
),
)
...
...
tests/test_routers.py
View file @
4cd49d5d
...
...
@@ -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<text>'
,
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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment