From 693a78ceee9e4f1fbf65df5ee66f0884b0d5ed1a Mon Sep 17 00:00:00 2001 From: Masco Kaliyamoorthy Date: Mon, 9 Feb 2015 14:27:51 +0530 Subject: [PATCH] added filter for keypair and security and access tables client side filter is missing in keypair table and security and access table. this patch adding the client side filter on both of the above mentioned tables. Change-Id: I71a89fb7e1763eb1a6f242ae6d007d55afe51a68 Closes-Bug: #1419649 --- .../project/access_and_security/keypairs/tables.py | 12 +++++++++++- .../access_and_security/security_groups/tables.py | 11 ++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/openstack_dashboard/dashboards/project/access_and_security/keypairs/tables.py b/openstack_dashboard/dashboards/project/access_and_security/keypairs/tables.py index 682df249af..e87146c120 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/keypairs/tables.py +++ b/openstack_dashboard/dashboards/project/access_and_security/keypairs/tables.py @@ -78,6 +78,15 @@ class CreateKeyPair(tables.LinkAction): return True +class KeypairsFilterAction(tables.FilterAction): + + def filter(self, table, keypairs, filter_string): + """Naive case-insensitive search.""" + query = filter_string.lower() + return [keypair for keypair in keypairs + if query in keypair.name.lower()] + + class KeypairsTable(tables.DataTable): detail_link = "horizon:project:access_and_security:keypairs:detail" @@ -91,5 +100,6 @@ class KeypairsTable(tables.DataTable): class Meta(object): name = "keypairs" verbose_name = _("Key Pairs") - table_actions = (CreateKeyPair, ImportKeyPair, DeleteKeyPairs,) + table_actions = (CreateKeyPair, ImportKeyPair, DeleteKeyPairs, + KeypairsFilterAction,) row_actions = (DeleteKeyPairs,) diff --git a/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py b/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py index 2b5784e516..1297246b3d 100644 --- a/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py +++ b/openstack_dashboard/dashboards/project/access_and_security/security_groups/tables.py @@ -128,6 +128,15 @@ class ManageRules(policy.PolicyTargetMixin, tables.LinkAction): return POLICY_CHECK(policy, request, policy_target) +class SecurityGroupsFilterAction(tables.FilterAction): + + def filter(self, table, security_groups, filter_string): + """Naive case-insensitive search.""" + query = filter_string.lower() + return [security_group for security_group in security_groups + if query in security_group.name.lower()] + + class SecurityGroupsTable(tables.DataTable): name = tables.Column("name", verbose_name=_("Name")) description = tables.Column("description", verbose_name=_("Description")) @@ -138,7 +147,7 @@ class SecurityGroupsTable(tables.DataTable): class Meta(object): name = "security_groups" verbose_name = _("Security Groups") - table_actions = (CreateGroup, DeleteGroup) + table_actions = (CreateGroup, DeleteGroup, SecurityGroupsFilterAction) row_actions = (ManageRules, EditGroup, DeleteGroup)