Only set .action attribute in override_method if it already existed on the view

This commit is contained in:
Tom Christie 2014-08-18 20:56:17 +01:00
parent 01986fc80e
commit 97d8f037cc

View File

@ -46,13 +46,16 @@ class override_method(object):
def __enter__(self):
self.view.request = clone_request(self.request, self.method)
action_map = getattr(self.view, 'action_map', {})
self.view.action = action_map.get(self.method.lower())
if self.action is not None:
# For viewsets we also set the `.action` attribute.
action_map = getattr(self.view, 'action_map', {})
self.view.action = action_map.get(self.method.lower())
return self.view.request
def __exit__(self, *args, **kwarg):
self.view.action = self.action
self.view.request = self.request
if self.action is not None:
self.view.action = self.action
class Empty(object):