Skip to content

Commit

Permalink
Fix 'metadata' action on viewsets. Closes #3158. Closes #3157. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Jul 16, 2015
1 parent 6b08e97 commit a9f1d99
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions rest_framework/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ def view(request, *args, **kwargs):
if hasattr(self, 'get') and not hasattr(self, 'head'):
self.head = self.get

# Explicitly map `options` requests to an (implicit) action named
# 'metadata'. This action doesn't actually exist as a named method,
# because, unlike other methods, we always route to it.
if hasattr(self, 'options'):
self.action_map['options'] = 'metadata'

# And continue as usual
return self.dispatch(request, *args, **kwargs)

Expand All @@ -112,7 +106,14 @@ def initialize_request(self, request, *args, **kwargs):
depending on the request method.
"""
request = super(ViewSetMixin, self).initialize_request(request, *args, **kwargs)
self.action = self.action_map.get(request.method.lower())
method = request.method.lower()
if method == 'options':
# This is a special case as we always provide handling for the
# options method in the base `View` class.
# Unlike the other explicitly defined actions, 'metadata' is implict.
self.action = 'metadata'
else:
self.action = self.action_map.get(method)
return request


Expand Down

0 comments on commit a9f1d99

Please sign in to comment.