mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-08 14:24:48 +03:00
Allow multiple @detail_route and/or @list_route for the same URL but different HTTP methods.
This commit is contained in:
parent
970bfe16ec
commit
6e18ed7dc8
|
@ -166,20 +166,22 @@ class SimpleRouter(BaseRouter):
|
||||||
list_routes.append((httpmethods, methodname))
|
list_routes.append((httpmethods, methodname))
|
||||||
|
|
||||||
def _get_dynamic_routes(route, dynamic_routes):
|
def _get_dynamic_routes(route, dynamic_routes):
|
||||||
ret = []
|
routes_map = OrderedDict()
|
||||||
for httpmethods, methodname in dynamic_routes:
|
for httpmethods, methodname in dynamic_routes:
|
||||||
method_kwargs = getattr(viewset, methodname).kwargs
|
method_kwargs = getattr(viewset, methodname).kwargs
|
||||||
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
|
url_path = initkwargs.pop("url_path", None) or methodname
|
||||||
ret.append(Route(
|
url = replace_methodname(route.url, url_path)
|
||||||
url=replace_methodname(route.url, url_path),
|
if url not in routes_map:
|
||||||
mapping=dict((httpmethod, methodname) for httpmethod in httpmethods),
|
routes_map[url] = {
|
||||||
name=replace_methodname(route.name, url_path),
|
'mapping': {},
|
||||||
initkwargs=initkwargs,
|
'name': replace_methodname(route.name, url_path),
|
||||||
))
|
'initkwargs': initkwargs
|
||||||
|
}
|
||||||
|
routes_map[url]['mapping'].update(dict((httpmethod, methodname) for httpmethod in httpmethods))
|
||||||
|
|
||||||
return ret
|
return list(Route(url=url, **args) for url, args in routes_map.items())
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
for route in self.routes:
|
for route in self.routes:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user