Add Filter Action to Instance Views

The Instances page in both admin section and project
section doesn't support the filter action yet. This
feature is however implemented for the Projects page
and Users page. So added this feature to the Instances
page.

Fixes bug #1169084

Change-Id: I76e77a61f032e96f2d8d69a22d2caab2108c2aa8
This commit is contained in:
Kannan Manickam
2013-04-15 01:58:29 -07:00
parent e4541a6175
commit a351f1a2fd
2 changed files with 18 additions and 2 deletions

View File

@@ -439,6 +439,14 @@ TASK_DISPLAY_CHOICES = (
)
class InstancesFilterAction(tables.FilterAction):
def filter(self, table, instances, filter_string):
""" Naive case-insensitive search. """
q = filter_string.lower()
return [instance for instance in instances
if q in instance.name.lower()]
class InstancesTable(tables.DataTable):
TASK_STATUS_CHOICES = (
(None, True),
@@ -480,7 +488,7 @@ class InstancesTable(tables.DataTable):
verbose_name = _("Instances")
status_columns = ["status", "task"]
row_class = UpdateRow
table_actions = (LaunchLink, TerminateInstance)
table_actions = (LaunchLink, TerminateInstance, InstancesFilterAction)
row_actions = (ConfirmResize, RevertResize, CreateSnapshot,
SimpleAssociateIP, AssociateIP,
SimpleDisassociateIP, EditInstance,