Commit bdc64d4e by Yannick PEROUX

Fix removal of url_path on @detail_route and @list_route. Fix # #2583

SimpleRouter.get_routes was popping out the url_path kwarg from
list_route and detail_route decorators. This was causing troubles
when the route was re-used, for example if the viewset was
inherited.
parent b69032f3
...@@ -171,9 +171,9 @@ class SimpleRouter(BaseRouter): ...@@ -171,9 +171,9 @@ class SimpleRouter(BaseRouter):
# Dynamic detail routes (@detail_route decorator) # Dynamic detail routes (@detail_route decorator)
for httpmethods, methodname in detail_routes: for httpmethods, methodname in detail_routes:
method_kwargs = getattr(viewset, methodname).kwargs method_kwargs = getattr(viewset, methodname).kwargs
url_path = method_kwargs.pop("url_path", None) or methodname
initkwargs = route.initkwargs.copy() initkwargs = route.initkwargs.copy()
initkwargs.update(method_kwargs) initkwargs.update(method_kwargs)
url_path = initkwargs.pop("url_path", None) or methodname
ret.append(Route( ret.append(Route(
url=replace_methodname(route.url, url_path), url=replace_methodname(route.url, url_path),
mapping=dict((httpmethod, methodname) for httpmethod in httpmethods), mapping=dict((httpmethod, methodname) for httpmethod in httpmethods),
...@@ -184,9 +184,9 @@ class SimpleRouter(BaseRouter): ...@@ -184,9 +184,9 @@ class SimpleRouter(BaseRouter):
# Dynamic list routes (@list_route decorator) # Dynamic list routes (@list_route decorator)
for httpmethods, methodname in list_routes: for httpmethods, methodname in list_routes:
method_kwargs = getattr(viewset, methodname).kwargs method_kwargs = getattr(viewset, methodname).kwargs
url_path = method_kwargs.pop("url_path", None) or methodname
initkwargs = route.initkwargs.copy() initkwargs = route.initkwargs.copy()
initkwargs.update(method_kwargs) initkwargs.update(method_kwargs)
url_path = initkwargs.pop("url_path", None) or methodname
ret.append(Route( ret.append(Route(
url=replace_methodname(route.url, url_path), url=replace_methodname(route.url, url_path),
mapping=dict((httpmethod, methodname) for httpmethod in httpmethods), mapping=dict((httpmethod, methodname) for httpmethod in httpmethods),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment