Ability to override default method names by customizing it

This commit is contained in:
tanwanirahul 2014-11-03 14:43:53 +01:00
parent 96bb77dc35
commit d972df7c9c

View File

@ -176,23 +176,27 @@ class SimpleRouter(BaseRouter):
if isinstance(route, DynamicDetailRoute):
# Dynamic detail routes (@detail_route decorator)
for httpmethods, methodname in detail_routes:
method_kwargs = getattr(viewset, methodname).kwargs
custom_method_name = method_kwargs.pop("custom_method_name", None) or methodname
initkwargs = route.initkwargs.copy()
initkwargs.update(getattr(viewset, methodname).kwargs)
initkwargs.update(method_kwargs)
ret.append(Route(
url=replace_methodname(route.url, methodname),
url=replace_methodname(route.url, custom_method_name),
mapping=dict((httpmethod, methodname) for httpmethod in httpmethods),
name=replace_methodname(route.name, methodname),
name=replace_methodname(route.name, custom_method_name),
initkwargs=initkwargs,
))
elif isinstance(route, DynamicListRoute):
# Dynamic list routes (@list_route decorator)
for httpmethods, methodname in list_routes:
method_kwargs = getattr(viewset, methodname).kwargs
custom_method_name = method_kwargs.pop("custom_method_name", None) or methodname
initkwargs = route.initkwargs.copy()
initkwargs.update(getattr(viewset, methodname).kwargs)
initkwargs.update(method_kwargs)
ret.append(Route(
url=replace_methodname(route.url, methodname),
url=replace_methodname(route.url, custom_method_name),
mapping=dict((httpmethod, methodname) for httpmethod in httpmethods),
name=replace_methodname(route.name, methodname),
name=replace_methodname(route.name, custom_method_name),
initkwargs=initkwargs,
))
else: