mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Wrap action decorator for old url_name behavior
This commit is contained in:
parent
bf561559bd
commit
2cc1bf7cf6
|
@ -148,13 +148,7 @@ def action(methods=None, detail=None, url_path=None, url_name=None, **kwargs):
|
|||
func.bind_to_methods = methods
|
||||
func.detail = detail
|
||||
func.url_path = url_path if url_path else func.__name__
|
||||
func.url_name = url_name
|
||||
if not url_name:
|
||||
# Remove in 3.10
|
||||
if kwargs.get('_url_name_from_path', False):
|
||||
func.url_name = func.url_path.replace('_', '-')
|
||||
else:
|
||||
func.url_name = func.__name__.replace('_', '-')
|
||||
func.url_name = url_name if url_name else func.__name__.replace('_', '-')
|
||||
func.kwargs = kwargs
|
||||
return func
|
||||
return decorator
|
||||
|
@ -169,7 +163,13 @@ def detail_route(methods=None, **kwargs):
|
|||
"`action`, which accepts a `detail` bool. Use `@action(detail=True)` instead.",
|
||||
PendingDeprecationWarning, stacklevel=2
|
||||
)
|
||||
return action(methods, detail=True, _url_name_from_path=True, **kwargs)
|
||||
|
||||
def decorator(func):
|
||||
func = action(methods, detail=True, **kwargs)(func)
|
||||
if 'url_name' not in kwargs:
|
||||
func.url_name = func.url_path.replace('_', '-')
|
||||
return func
|
||||
return decorator
|
||||
|
||||
|
||||
def list_route(methods=None, **kwargs):
|
||||
|
@ -181,4 +181,10 @@ def list_route(methods=None, **kwargs):
|
|||
"`action`, which accepts a `detail` bool. Use `@action(detail=False)` instead.",
|
||||
PendingDeprecationWarning, stacklevel=2
|
||||
)
|
||||
return action(methods, detail=False, _url_name_from_path=True, **kwargs)
|
||||
|
||||
def decorator(func):
|
||||
func = action(methods, detail=False, **kwargs)(func)
|
||||
if 'url_name' not in kwargs:
|
||||
func.url_name = func.url_path.replace('_', '-')
|
||||
return func
|
||||
return decorator
|
||||
|
|
Loading…
Reference in New Issue
Block a user