Update admin filter first setting to a dict

Previously the ADMIN_FILTER_DATA_FIRST setting was a True/False
setting that was taking over all the admin views leaving
operators without the opportunity to set this setting to views
individually.

This patch changes the setting to a dict where it can be specified
which panels/views will implement this setting individually.

Implements blueprint: admin-views-filter-first

Change-Id: I50deab878f68c1cc519aa9b47feaa2c58bb8eacc
This commit is contained in:
Luis Daniel Castellanos 2016-09-13 14:34:41 -05:00
parent 7419a6f365
commit e15b61f58a
12 changed files with 54 additions and 23 deletions

View File

@ -1659,17 +1659,39 @@ no restriction for both IPv4 and IPv6.
Example: ``{'ipv4': ['192.168.0.0/16', '10.0.0.0/8'], 'ipv6': ['fc00::/7',]}``
``ADMIN_FILTER_DATA_FIRST``
``FILTER_DATA_FIRST``
---------------------------
.. versionadded:: 10.0.0(Newton)
Default: ``False``
Default::
If True, when admin views load, an empty table will be rendered and the
user will be asked to provide a search criteria first (in case no search
{
'admin.instances': False,
'admin.images': False,
'admin.networks': False,
'admin.routers': False,
'admin.volumes': False
}
If the dict key-value is True, when the view loads, an empty table will be rendered
and the user will be asked to provide a search criteria first (in case no search
criteria was provided) before loading any data.
Examples::
Override the dict::
{
'admin.instances': True,
'admin.images': True,
'admin.networks': False,
'admin.routers': False,
'admin.volumes': False
}
Or, if you want to turn this on for an specific panel/view do: ``FILTER_DATA_FIRST['admin.instances'] = True``
``OPERATION_LOG_ENABLED``
-------------------------

View File

@ -68,7 +68,7 @@ class ImagesViewTest(test.BaseAdminViewTests):
self.assertEqual(len(res.context['images_table'].data),
len(self.images.list()))
@test.update_settings(ADMIN_FILTER_DATA_FIRST=True)
@test.update_settings(FILTER_DATA_FIRST={'admin.images': True})
def test_images_list_with_admin_filter_first(self):
res = self.client.get(reverse('horizon:admin:images:index'))
self.assertTemplateUsed(res, 'admin/images/index.html')

View File

@ -70,8 +70,8 @@ class IndexView(tables.DataTableView):
return images
filters = self.get_filters()
filter_first = getattr(settings, 'ADMIN_FILTER_DATA_FIRST', False)
if filter_first and \
filter_first = getattr(settings, 'FILTER_DATA_FIRST', {})
if filter_first.get('admin.images', False) and \
len(filters) == len(self.DEFAULT_FILTERS):
self._prev = False
self._more = False

View File

@ -401,7 +401,7 @@ class InstanceViewTest(test.BaseAdminViewTests):
self.assertRedirectsNoFollow(res, INDEX_URL)
@test.update_settings(ADMIN_FILTER_DATA_FIRST=True)
@test.update_settings(FILTER_DATA_FIRST={'admin.instances': True})
def test_index_with_admin_filter_first(self):
res = self.client.get(INDEX_URL)
self.assertTemplateUsed(res, 'admin/instances/index.html')

View File

@ -86,8 +86,8 @@ class AdminIndexView(tables.DataTableView):
# If filter_first is set and if there are not other filters
# selected, then search criteria must be provided and return an empty
# list
filter_first = getattr(settings, 'ADMIN_FILTER_DATA_FIRST', False)
if filter_first and \
filter_first = getattr(settings, 'FILTER_DATA_FIRST', {})
if filter_first.get('admin.instances', False) and \
len(search_opts) == len(default_search_opts):
self._needs_filter_first = True
self._more = False

View File

@ -762,7 +762,7 @@ class NetworkTests(test.BaseAdminViewTests):
self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.neutron: ('is_extension_supported',)})
@test.update_settings(ADMIN_FILTER_DATA_FIRST=True)
@test.update_settings(FILTER_DATA_FIRST={'admin.networks': True})
def test_networks_list_with_admin_filter_first(self):
api.neutron.is_extension_supported(
IsA(http.HttpRequest),

View File

@ -90,8 +90,9 @@ class IndexView(tables.DataTableView):
# If filter_first is set and if there are not other filters
# selected, then search criteria must be provided and return an
# empty list
filter_first = getattr(settings, 'ADMIN_FILTER_DATA_FIRST', False)
if filter_first and not search_opts:
filter_first = getattr(settings, 'FILTER_DATA_FIRST', {})
if filter_first.get('admin.networks', False) and \
not search_opts:
self._needs_filter_first = True
return []
self._needs_filter_first = False

View File

@ -188,7 +188,7 @@ class RouterTests(test.BaseAdminViewTests, r_test.RouterTests):
self.assertIn('Deleted Router: ' + router.name,
res.content.decode('utf-8'))
@test.update_settings(ADMIN_FILTER_DATA_FIRST=True)
@test.update_settings(FILTER_DATA_FIRST={'admin.routers': True})
def test_routers_list_with_admin_filter_first(self):
res = self.client.get(self.INDEX_URL)
self.assertTemplateUsed(res, '%s/routers/index.html' % self.DASHBOARD)

View File

@ -44,8 +44,8 @@ class IndexView(r_views.IndexView, n_views.IndexView):
# If admin_filter_first is set and if there are not other filters
# selected, then search criteria must be provided and return an
# empty list
filter_first = getattr(settings, 'ADMIN_FILTER_DATA_FIRST', False)
if filter_first and not filters:
filter_first = getattr(settings, 'FILTER_DATA_FIRST', {})
if filter_first.get('admin.routers', False) and not filters:
self._needs_filter_first = True
return []
self._needs_filter_first = False

View File

@ -47,12 +47,13 @@ class VolumeTab(volumes_tabs.PagedTableMixin, tabs.TableTab,
default_filters = {'all_tenants': True}
filters = self.get_filters(default_filters.copy())
filter_first = getattr(settings, 'ADMIN_FILTER_DATA_FIRST', False)
filter_first = getattr(settings, 'FILTER_DATA_FIRST', {})
volumes = []
self.table.needs_filter_first = False
if filter_first and len(filters) == len(default_filters):
if filter_first.get('admin.volumes', False) and \
len(filters) == len(default_filters):
self.table.needs_filter_first = True
return volumes

View File

@ -312,7 +312,7 @@ class VolumeTests(test.BaseAdminViewTests):
snapshots = res.context['volume_snapshots_table'].data
self.assertItemsEqual(snapshots, expected_snapshots)
@override_settings(ADMIN_FILTER_DATA_FIRST=True)
@override_settings(FILTER_DATA_FIRST={'admin.volumes': True})
def test_volumes_tab_with_admin_filter_first(self):
res = self.client.get(INDEX_URL)

View File

@ -792,10 +792,17 @@ REST_API_REQUIRED_SETTINGS = ['OPENSTACK_HYPERVISOR_FEATURES',
# of data fetched by default when rendering the Overview panel.
#OVERVIEW_DAYS_RANGE = 1
# To allow operators to require admin users provide a search criteria first
# before loading any data into the admin views, set the following attribute to
# True
#ADMIN_FILTER_DATA_FIRST=False
# To allow operators to require users provide a search criteria first
# before loading any data into the views, set the following dict
# attributes to True in each one of the panels you want to enable this feature.
# Follow the convention <dashboard>.<view>
#FILTER_DATA_FIRST = {
# 'admin.instances': False,
# 'admin.images': False,
# 'admin.networks': False,
# 'admin.routers': False,
# 'admin.volumes': False
#}
# Dict used to restrict user private subnet cidr range.
# An empty list means that user input will not be restricted