mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 17:09:59 +03:00
Add underscore2dash
This commit is contained in:
parent
ec1b14174f
commit
09eeca136e
|
@ -120,7 +120,7 @@ def schema(view_inspector):
|
|||
return decorator
|
||||
|
||||
|
||||
def action(methods=None, detail=None, url_path=None, url_name=None, **kwargs):
|
||||
def action(methods=None, detail=None, url_path=None, url_name=None, underscore2dash=None, **kwargs):
|
||||
"""
|
||||
Mark a ViewSet method as a routable action.
|
||||
|
||||
|
@ -142,6 +142,11 @@ def action(methods=None, detail=None, url_path=None, url_name=None, **kwargs):
|
|||
func.mapping = MethodMapper(func, methods)
|
||||
|
||||
func.detail = detail
|
||||
if url_path:
|
||||
func.url_path = url_path
|
||||
else:
|
||||
func.url_path = func.__name__.replace('_', '-') if underscore2dash else func.__name__
|
||||
|
||||
func.url_path = url_path if url_path else func.__name__
|
||||
func.url_name = url_name if url_name else func.__name__.replace('_', '-')
|
||||
func.kwargs = kwargs
|
||||
|
|
|
@ -183,6 +183,13 @@ class ActionDecoratorTestCase(TestCase):
|
|||
'description': 'Description',
|
||||
}
|
||||
|
||||
def test_underscore2dash(self):
|
||||
@action(detail=True, underscore2dash=True)
|
||||
def test_action(request):
|
||||
"""Description"""
|
||||
|
||||
assert test_action.url_path == 'test-action'
|
||||
|
||||
def test_detail_required(self):
|
||||
with pytest.raises(AssertionError) as excinfo:
|
||||
@action()
|
||||
|
|
Loading…
Reference in New Issue
Block a user