Skip to content

Commit

Permalink
don't show batch actions if no table data is available
Browse files Browse the repository at this point in the history
bug 925671

Change-Id: I5e97d059f6f02f033f8dfb9aede01de75e514c98
  • Loading branch information
Thingee committed Feb 24, 2012
1 parent 5f9f5c1 commit 8cfd57b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions horizon/horizon/tables/actions.py
Expand Up @@ -57,6 +57,12 @@ def allowed(self, request, datum):
"""
return True

def _allowed(self, request, datum):
""" Default allowed checks for certain actions """
if isinstance(self, BatchAction) and not self.table.data:
return False
return self.allowed(request, datum)

def update(self, request, datum):
""" Allows per-action customization based on current conditions.
Expand Down
2 changes: 1 addition & 1 deletion horizon/horizon/tables/base.py
Expand Up @@ -665,7 +665,7 @@ def _populate_data_cache(self):
def _filter_action(self, action, request, datum=None):
try:
# Catch user errors in permission functions here
return action.allowed(request, datum)
return action._allowed(request, datum)
except Exception:
LOG.exception("Error while checking action permissions.")
return None
Expand Down
17 changes: 17 additions & 0 deletions horizon/horizon/tests/table_tests.py
Expand Up @@ -475,6 +475,23 @@ def test_table_actions(self):
self.assertEqual(list(req._messages)[0].message,
"Please select a row before taking that action.")

# At least one object in table
# BatchAction is available
req = self.factory.get('/my_url/')
self.table = MyTable(req, TEST_DATA_2)
self.assertQuerysetEqual(self.table.get_table_actions(),
['<MyFilterAction: filter>',
'<MyAction: delete>',
'<MyBatchAction: batch>'])

# Zero objects in table
# BatchAction not available
req = self.factory.get('/my_url/')
self.table = MyTable(req, None)
self.assertQuerysetEqual(self.table.get_table_actions(),
['<MyFilterAction: filter>',
'<MyAction: delete>'])

# Filtering
action_string = "my_table__filter__q"
req = self.factory.post('/my_url/', {action_string: '2'})
Expand Down

0 comments on commit 8cfd57b

Please sign in to comment.