Skip to content

Commit a8dff35

Browse files
author
Ryan P Kilby
committed
Use actual url_path/url_name in lieu of methodname
1 parent eafe0cc commit a8dff35

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

rest_framework/routers.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,6 @@ def escape_curly_brackets(url_path):
6464
return url_path
6565

6666

67-
def replace_methodname(format_string, methodname):
68-
"""
69-
Partially format a format_string, swapping out any
70-
'{methodname}' or '{methodnamehyphen}' components.
71-
"""
72-
methodnamehyphen = methodname.replace('_', '-')
73-
ret = format_string
74-
ret = ret.replace('{methodname}', methodname)
75-
ret = ret.replace('{methodnamehyphen}', methodnamehyphen)
76-
return ret
77-
78-
7967
def flatten(list_of_lists):
8068
"""
8169
Takes an iterable of iterables, returns a single iterable containing all items
@@ -130,8 +118,8 @@ class SimpleRouter(BaseRouter):
130118
# Generated using @list_route decorator
131119
# on methods of the viewset.
132120
DynamicRoute(
133-
url=r'^{prefix}/{methodname}{trailing_slash}$',
134-
name='{basename}-{methodnamehyphen}',
121+
url=r'^{prefix}/{url_path}{trailing_slash}$',
122+
name='{basename}-{url_name}',
135123
detail=False,
136124
initkwargs={}
137125
),
@@ -151,8 +139,8 @@ class SimpleRouter(BaseRouter):
151139
# Dynamically generated detail routes.
152140
# Generated using @detail_route decorator on methods of the viewset.
153141
DynamicRoute(
154-
url=r'^{prefix}/{lookup}/{methodname}{trailing_slash}$',
155-
name='{basename}-{methodnamehyphen}',
142+
url=r'^{prefix}/{lookup}/{url_path}{trailing_slash}$',
143+
name='{basename}-{url_name}',
156144
detail=True,
157145
initkwargs={}
158146
),
@@ -219,10 +207,10 @@ def _get_dynamic_route(self, route, action):
219207
url_path = escape_curly_brackets(action.url_path)
220208

221209
return Route(
222-
url=replace_methodname(route.url, url_path),
210+
url=route.url.replace('{url_path}', url_path),
223211
mapping={http_method: action.__name__
224212
for http_method in action.bind_to_methods},
225-
name=replace_methodname(route.name, action.url_name),
213+
name=route.name.replace('{url_name}', action.url_name),
226214
detail=route.detail,
227215
initkwargs=initkwargs,
228216
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy