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
5688d8b7
Commit
5688d8b7
authored
Feb 25, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2601 from k4nar/refactor_simplerouter
Remove duplicated code in routers.SimpleRouter
parents
90f1c04c
940cf2e2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
15 deletions
+11
-15
rest_framework/routers.py
+11
-15
No files found.
rest_framework/routers.py
View file @
5688d8b7
...
...
@@ -165,11 +165,9 @@ class SimpleRouter(BaseRouter):
else
:
list_routes
.
append
((
httpmethods
,
methodname
))
def
_get_dynamic_routes
(
route
,
dynamic_routes
):
ret
=
[]
for
route
in
self
.
routes
:
if
isinstance
(
route
,
DynamicDetailRoute
):
# Dynamic detail routes (@detail_route decorator)
for
httpmethods
,
methodname
in
detail_routes
:
for
httpmethods
,
methodname
in
dynamic_routes
:
method_kwargs
=
getattr
(
viewset
,
methodname
)
.
kwargs
initkwargs
=
route
.
initkwargs
.
copy
()
initkwargs
.
update
(
method_kwargs
)
...
...
@@ -180,19 +178,17 @@ class SimpleRouter(BaseRouter):
name
=
replace_methodname
(
route
.
name
,
url_path
),
initkwargs
=
initkwargs
,
))
return
ret
ret
=
[]
for
route
in
self
.
routes
:
if
isinstance
(
route
,
DynamicDetailRoute
):
# Dynamic detail routes (@detail_route decorator)
ret
+=
_get_dynamic_routes
(
route
,
detail_routes
)
elif
isinstance
(
route
,
DynamicListRoute
):
# Dynamic list routes (@list_route decorator)
for
httpmethods
,
methodname
in
list_routes
:
method_kwargs
=
getattr
(
viewset
,
methodname
)
.
kwargs
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
),
name
=
replace_methodname
(
route
.
name
,
url_path
),
initkwargs
=
initkwargs
,
))
ret
+=
_get_dynamic_routes
(
route
,
list_routes
)
else
:
# Standard route
ret
.
append
(
route
)
...
...
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