don't show batch actions if no table data is available
bug 925671 Change-Id: I5e97d059f6f02f033f8dfb9aede01de75e514c98
This commit is contained in:
@@ -57,6 +57,12 @@ class BaseAction(object):
|
||||
"""
|
||||
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.
|
||||
|
||||
|
||||
@@ -665,7 +665,7 @@ class DataTable(object):
|
||||
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
|
||||
|
||||
@@ -475,6 +475,23 @@ class DataTableTests(test.TestCase):
|
||||
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'})
|
||||
|
||||
Reference in New Issue
Block a user