diff options
| -rw-r--r-- | rest_framework/decorators.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/rest_framework/decorators.py b/rest_framework/decorators.py index 1ca176f2..18e41a18 100644 --- a/rest_framework/decorators.py +++ b/rest_framework/decorators.py @@ -108,53 +108,54 @@ def permission_classes(permission_classes): return decorator -def link(**kwargs): +def detail_route(methods=['get'], **kwargs): """ - Used to mark a method on a ViewSet that should be routed for detail GET requests. + Used to mark a method on a ViewSet that should be routed for detail requests. """ - msg = 'link is pending deprecation. Use detail_route instead.' - warnings.warn(msg, PendingDeprecationWarning, stacklevel=2) def decorator(func): - func.bind_to_methods = ['get'] + func.bind_to_methods = methods func.detail = True func.kwargs = kwargs return func return decorator -def action(methods=['post'], **kwargs): +def list_route(methods=['get'], **kwargs): """ - Used to mark a method on a ViewSet that should be routed for detail POST requests. + Used to mark a method on a ViewSet that should be routed for list requests. """ - msg = 'action is pending deprecation. Use detail_route instead.' - warnings.warn(msg, PendingDeprecationWarning, stacklevel=2) def decorator(func): func.bind_to_methods = methods - func.detail = True + func.detail = False func.kwargs = kwargs return func return decorator +# These are now pending deprecation, in favor of `detail_route` and `list_route`. -def detail_route(methods=['get'], **kwargs): +def link(**kwargs): """ - Used to mark a method on a ViewSet that should be routed for detail requests. + Used to mark a method on a ViewSet that should be routed for detail GET requests. """ + msg = 'link is pending deprecation. Use detail_route instead.' + warnings.warn(msg, PendingDeprecationWarning, stacklevel=2) def decorator(func): - func.bind_to_methods = methods + func.bind_to_methods = ['get'] func.detail = True func.kwargs = kwargs return func return decorator -def list_route(methods=['get'], **kwargs): +def action(methods=['post'], **kwargs): """ - Used to mark a method on a ViewSet that should be routed for list requests. + Used to mark a method on a ViewSet that should be routed for detail POST requests. """ + msg = 'action is pending deprecation. Use detail_route instead.' + warnings.warn(msg, PendingDeprecationWarning, stacklevel=2) def decorator(func): func.bind_to_methods = methods - func.detail = False + func.detail = True func.kwargs = kwargs return func - return decorator + return decorator
\ No newline at end of file |
