Skip to content

Commit

Permalink
Merge pull request #34 from dukebody/master
Browse files Browse the repository at this point in the history
Raise original object action KeyError instead of wrapping it
  • Loading branch information
crccheck committed Sep 16, 2015
2 parents bff321f + 0a130e1 commit ba358f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions django_object_actions/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ def test_intermediate_page_with_post_works(self):
def test_undefined_tool_404s(self):
response = self.client.get('/admin/polls/choice/1/tools/weeeewoooooo/')
self.assertEqual(response.status_code, 404)

def test_key_error_tool_500s(self):
self.assertRaises(KeyError, self.client.get,
'/admin/polls/choice/1/tools/raise_key_error/')
3 changes: 2 additions & 1 deletion django_object_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ def get(self, request, **kwargs):
# is instantiated with `model` and the urlpattern has `pk`.
obj = self.get_object()
try:
ret = self.tools[kwargs['tool']](request, obj)
tool = self.tools[kwargs['tool']]
except KeyError:
raise Http404(u'Tool does not exist')
ret = tool(request, obj)
if isinstance(ret, HttpResponse):
return ret
back = request.path.rsplit('/', 3)[0] + '/'
Expand Down
5 changes: 4 additions & 1 deletion example_project/polls/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ def edit_poll(self, request, obj):
url = reverse('admin:polls_poll_change', args=(obj.poll.pk,))
return HttpResponseRedirect(url)

def raise_key_error(self, request, obj):
raise KeyError

objectactions = ('increment_vote', 'decrement_vote', 'reset_vote',
'edit_poll')
'edit_poll', 'raise_key_error')
actions = ['increment_vote']

admin.site.register(Choice, ChoiceAdmin)
Expand Down

0 comments on commit ba358f7

Please sign in to comment.