From 9d7b751f5fc61e5862b393a31c42e084c63441d9 Mon Sep 17 00:00:00 2001 From: Luis Daniel Castellanos Date: Fri, 2 Sep 2016 10:16:54 -0500 Subject: [PATCH] Implement admin_filter_first setting in Admin>Volumes Implemented the ADMIN_FILTER_DATA_FIRST setting in Admin>Volumes View (volumes Tab) Implements blueprint: admin-views-filter-first Depends-On: I007af8d4aef33656752796250f4177ddf01dd78b Change-Id: I539c2ae4b420892085227bef5277896c0f1227c0 --- openstack_dashboard/dashboards/admin/volumes/tabs.py | 11 ++++++++++- openstack_dashboard/dashboards/admin/volumes/tests.py | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/openstack_dashboard/dashboards/admin/volumes/tabs.py b/openstack_dashboard/dashboards/admin/volumes/tabs.py index f052df0677..0548cf4d87 100644 --- a/openstack_dashboard/dashboards/admin/volumes/tabs.py +++ b/openstack_dashboard/dashboards/admin/volumes/tabs.py @@ -11,6 +11,7 @@ # under the License. from collections import OrderedDict +from django.conf import settings from django.utils.translation import ugettext_lazy as _ from horizon import exceptions @@ -42,9 +43,17 @@ class VolumeTab(volumes_tabs.PagedTableMixin, tabs.TableTab, def get_volumes_data(self): default_filters = {'all_tenants': True} - filters = self.get_filters(default_filters) + + filters = self.get_filters(default_filters.copy()) + filter_first = getattr(settings, 'ADMIN_FILTER_DATA_FIRST', False) volumes = [] + self.table.needs_filter_first = False + + if filter_first and len(filters) == len(default_filters): + self.table.needs_filter_first = True + return volumes + if 'project' in filters: # Keystone returns a tuple ([],false) where the first element is # tenant list that's why the 0 is hardcoded below diff --git a/openstack_dashboard/dashboards/admin/volumes/tests.py b/openstack_dashboard/dashboards/admin/volumes/tests.py index 11708f1e02..e862925463 100644 --- a/openstack_dashboard/dashboards/admin/volumes/tests.py +++ b/openstack_dashboard/dashboards/admin/volumes/tests.py @@ -311,3 +311,11 @@ class VolumeTests(test.BaseAdminViewTests): url=url, has_more=True, has_prev=False) snapshots = res.context['volume_snapshots_table'].data self.assertItemsEqual(snapshots, expected_snapshots) + + @override_settings(ADMIN_FILTER_DATA_FIRST=True) + def test_volumes_tab_with_admin_filter_first(self): + res = self.client.get(INDEX_URL) + + self.assertTemplateUsed(res, 'admin/volumes/index.html') + volumes = res.context['volumes_table'].data + self.assertItemsEqual(volumes, [])