Change from client filter to server filter in metadata page

In metadata page, we can only filter within current page.
But it is not useful. So this patch will change to get filtered results
from server.
At the moment, glance is only providing 'Resource Types' as a filter key.

Change-Id: I96d4eee2cba2413725c5871062889c0c61e82593
Closes-Bug: #1586231
Partial-Implements: blueprint server-side-filtering
This commit is contained in:
Kenji Ishii 2016-05-27 11:40:21 +09:00
parent 2bad139137
commit acf67e027d
3 changed files with 21 additions and 4 deletions

View File

@ -82,7 +82,8 @@ class ManageResourceTypeAssociations(tables.LinkAction):
class AdminMetadataFilterAction(tables.FilterAction):
pass
filter_type = "server"
filter_choices = (('resource_types', _("Resource Types ="), True),)
class UpdateRow(tables.Row):

View File

@ -49,7 +49,8 @@ class MetadataDefinitionsView(test.BaseAdminViewTests):
IsA(http.HttpRequest),
sort_dir='asc',
marker=None,
paginate=True).AndReturn((namespace_list, False, False))
paginate=True,
filters={}).AndReturn((namespace_list, False, False))
self.mox.ReplayAll()
res = self.client.get(reverse(constants.METADATA_INDEX_URL))
@ -89,7 +90,8 @@ class MetadataDefinitionsView(test.BaseAdminViewTests):
IsA(http.HttpRequest),
sort_dir='asc',
marker=None,
paginate=True).AndReturn((namespace_list, False, False))
paginate=True,
filters={}).AndReturn((namespace_list, False, False))
self.mox.ReplayAll()
res = self.client.get(reverse(constants.METADATA_INDEX_URL))

View File

@ -59,12 +59,15 @@ class AdminIndexView(tables.DataTableView):
marker = self.request.GET.get(
admin_tables.AdminNamespacesTable._meta.pagination_param, None)
filters = self.get_filters()
try:
namespaces, self._more, self._prev =\
glance.metadefs_namespace_list(self.request,
marker=marker,
paginate=True,
sort_dir=sort_dir)
sort_dir=sort_dir,
filters=filters)
if prev_marker is not None:
namespaces = sorted(namespaces,
@ -77,6 +80,17 @@ class AdminIndexView(tables.DataTableView):
exceptions.handle(self.request, msg)
return namespaces
def get_filters(self, filters=None):
if not filters:
filters = {}
filter_field = self.table.get_filter_field()
filter_action = self.table._meta._filter_action
if filter_action.is_api_filter(filter_field):
filter_string = self.table.get_filter_string().strip()
if filter_field and filter_string:
filters[filter_field] = filter_string
return filters
class CreateView(forms.ModalFormView):
form_class = admin_forms.CreateNamespaceForm