mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
.action attribute on viewsets
This commit is contained in:
parent
538d2e35e7
commit
660d240517
|
@ -59,6 +59,10 @@ class ViewSetMixin(object):
|
||||||
|
|
||||||
def view(request, *args, **kwargs):
|
def view(request, *args, **kwargs):
|
||||||
self = cls(**initkwargs)
|
self = cls(**initkwargs)
|
||||||
|
# We also store the mapping of request methods to actions,
|
||||||
|
# so that we can later set the action attribute.
|
||||||
|
# eg. `self.action = 'list'` on an incoming GET request.
|
||||||
|
self.action_map = actions
|
||||||
|
|
||||||
# Bind methods to actions
|
# Bind methods to actions
|
||||||
# This is the bit that's different to a standard view
|
# This is the bit that's different to a standard view
|
||||||
|
@ -87,6 +91,15 @@ class ViewSetMixin(object):
|
||||||
view.suffix = initkwargs.get('suffix', None)
|
view.suffix = initkwargs.get('suffix', None)
|
||||||
return view
|
return view
|
||||||
|
|
||||||
|
def initialize_request(self, request, *args, **kargs):
|
||||||
|
"""
|
||||||
|
Set the `.action` attribute on the view,
|
||||||
|
depending on the request method.
|
||||||
|
"""
|
||||||
|
request = super(ViewSetMixin, self).initialize_request(request, *args, **kargs)
|
||||||
|
self.action = self.action_map.get(request.method.lower())
|
||||||
|
return request
|
||||||
|
|
||||||
|
|
||||||
class ViewSet(ViewSetMixin, views.APIView):
|
class ViewSet(ViewSetMixin, views.APIView):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user