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
90f1c04c
Commit
90f1c04c
authored
Feb 25, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2595 from k4nar/fix_url_path
Fix url_path on dynamic routes for inherited viewsets. Fix #2583
parents
b69032f3
9cafdd18
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
rest_framework/routers.py
+2
-2
tests/test_routers.py
+12
-2
No files found.
rest_framework/routers.py
View file @
90f1c04c
...
...
@@ -171,9 +171,9 @@ class SimpleRouter(BaseRouter):
# Dynamic detail routes (@detail_route decorator)
for
httpmethods
,
methodname
in
detail_routes
:
method_kwargs
=
getattr
(
viewset
,
methodname
)
.
kwargs
url_path
=
method_kwargs
.
pop
(
"url_path"
,
None
)
or
methodname
initkwargs
=
route
.
initkwargs
.
copy
()
initkwargs
.
update
(
method_kwargs
)
url_path
=
initkwargs
.
pop
(
"url_path"
,
None
)
or
methodname
ret
.
append
(
Route
(
url
=
replace_methodname
(
route
.
url
,
url_path
),
mapping
=
dict
((
httpmethod
,
methodname
)
for
httpmethod
in
httpmethods
),
...
...
@@ -184,9 +184,9 @@ class SimpleRouter(BaseRouter):
# Dynamic list routes (@list_route decorator)
for
httpmethods
,
methodname
in
list_routes
:
method_kwargs
=
getattr
(
viewset
,
methodname
)
.
kwargs
url_path
=
method_kwargs
.
pop
(
"url_path"
,
None
)
or
methodname
initkwargs
=
route
.
initkwargs
.
copy
()
initkwargs
.
update
(
method_kwargs
)
url_path
=
initkwargs
.
pop
(
"url_path"
,
None
)
or
methodname
ret
.
append
(
Route
(
url
=
replace_methodname
(
route
.
url
,
url_path
),
mapping
=
dict
((
httpmethod
,
methodname
)
for
httpmethod
in
httpmethods
),
...
...
tests/test_routers.py
View file @
90f1c04c
...
...
@@ -302,12 +302,16 @@ class DynamicListAndDetailViewSet(viewsets.ViewSet):
return
Response
({
'method'
:
'link2'
})
class
SubDynamicListAndDetailViewSet
(
DynamicListAndDetailViewSet
):
pass
class
TestDynamicListAndDetailRouter
(
TestCase
):
def
setUp
(
self
):
self
.
router
=
SimpleRouter
()
def
test_list_and_detail_route_decorators
(
self
):
routes
=
self
.
router
.
get_routes
(
DynamicListAndDetailViewS
et
)
def
_test_list_and_detail_route_decorators
(
self
,
viewset
):
routes
=
self
.
router
.
get_routes
(
views
et
)
decorator_routes
=
[
r
for
r
in
routes
if
not
(
r
.
name
.
endswith
(
'-list'
)
or
r
.
name
.
endswith
(
'-detail'
))]
MethodNamesMap
=
namedtuple
(
'MethodNamesMap'
,
'method_name url_path'
)
...
...
@@ -336,3 +340,9 @@ class TestDynamicListAndDetailRouter(TestCase):
else
:
method_map
=
'get'
self
.
assertEqual
(
route
.
mapping
[
method_map
],
method_name
)
def
test_list_and_detail_route_decorators
(
self
):
self
.
_test_list_and_detail_route_decorators
(
DynamicListAndDetailViewSet
)
def
test_inherited_list_and_detail_route_decorators
(
self
):
self
.
_test_list_and_detail_route_decorators
(
SubDynamicListAndDetailViewSet
)
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