override_method should substitute action

A view's action is dependent on the request method. When overriding the method (e.g. to generate a form for a POST request on a GET call to the browseable API), the action should be updated as well. Otherwise, viewset functions may be in a weird limbo state where a 'list' action has a POST method.
This commit is contained in:
Andrew Fong 2014-08-16 15:05:46 -07:00
parent 38a0e3e627
commit 5f63d31b00

View File

@ -42,12 +42,16 @@ class override_method(object):
self.view = view
self.request = request
self.method = method
self.action = getattr(view, 'action', None)
def __enter__(self):
self.view.request = clone_request(self.request, self.method)
action_map = getattr(self, '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