Merge "Fixing possible exception on tables in tabs"

This commit is contained in:
Jenkins 2013-10-22 12:09:03 +00:00 committed by Gerrit Code Review
commit cc8951748b

View File

@ -138,14 +138,16 @@ class TabbedTableView(tables.MultiTableMixin, TabView):
def post(self, request, *args, **kwargs):
# Direct POST to it's appropriate tab
targetslug = request.POST['action'].split('__')[0]
tabs = self.get_tabs(self.request, **self.kwargs).get_tabs()
matches = [tab for tab in tabs if tab.slug == targetslug]
if matches:
# Call POST on first match only. There shouldn't be a case where
# multiple tabs have the same slug and processing the request twice
# could lead to unpredictable behavior.
matches[0].post(request, *args, **kwargs)
# Note some table actions like filter do not have an 'action'
if 'action' in request.POST:
targetslug = request.POST['action'].split('__')[0]
tabs = self.get_tabs(self.request, **self.kwargs).get_tabs()
matches = [tab for tab in tabs if tab.slug == targetslug]
if matches:
# Call POST on first match only. There shouldn't be a case
# where multiple tabs have the same slug and processing the
# request twice could lead to unpredictable behavior.
matches[0].post(request, *args, **kwargs)
# GET and POST handling are the same
return self.get(request, *args, **kwargs)