diff --git a/horizon/api/glance.py b/horizon/api/glance.py index 5fd84a8..06aea1e 100644 --- a/horizon/api/glance.py +++ b/horizon/api/glance.py @@ -51,8 +51,9 @@ def image_get(request, image_id): return glanceclient(request).images.get(image_id) -def image_list_detailed(request): - return glanceclient(request).images.list() +def image_list_detailed(request, limit=None, filters=None): + return glanceclient(request).images.list(limit=limit, + filters=filters) def image_update(request, image_id, **kwargs): diff --git a/horizon/dashboards/nova/images_and_snapshots/views.py b/horizon/dashboards/nova/images_and_snapshots/views.py index aef5e36..0aca501 100644 --- a/horizon/dashboards/nova/images_and_snapshots/views.py +++ b/horizon/dashboards/nova/images_and_snapshots/views.py @@ -44,7 +44,7 @@ class IndexView(tables.MultiTableView): def get_images_data(self): try: - all_images = api.image_list_detailed(self.request) + all_images = api.image_list_detailed(self.request, limit=9999) images = [im for im in all_images if im.container_format not in ['aki', 'ari'] and im.properties.get("image_type", '') != "snapshot"] diff --git a/horizon/dashboards/syspanel/images/views.py b/horizon/dashboards/syspanel/images/views.py index d4821c5..97601b5 100644 --- a/horizon/dashboards/syspanel/images/views.py +++ b/horizon/dashboards/syspanel/images/views.py @@ -40,7 +40,8 @@ class IndexView(tables.DataTableView): def get_data(self): images = [] try: - images = api.image_list_detailed(self.request) + # Get 9999 items default. + images = api.image_list_detailed(self.request, limit=9999) except: msg = _('Unable to retrieve image list.') exceptions.handle(self.request, msg) diff --git a/horizon/tables/base.py b/horizon/tables/base.py index 7152c30..243d7da 100644 --- a/horizon/tables/base.py +++ b/horizon/tables/base.py @@ -34,6 +34,7 @@ from django.utils.http import urlencode from django.utils.translation import ugettext_lazy as _ from django.utils.safestring import mark_safe from django.utils import termcolors +from django.core.paginator import Paginator, InvalidPage, EmptyPage from horizon import exceptions from horizon.utils import html @@ -1074,6 +1075,19 @@ class DataTable(object): try: for datum in self.filtered_data: rows.append(self._meta.row_class(self, datum)) + # Show 10 rows per page + paginator = Paginator(rows, 10) + # Make sure page request is an int. If not, deliver first page. + try: + page = int(self._meta.request.GET.get('page', '1')) + except ValueError: + page = 1 + # If page request (9999) is out of range, + # deliver last page of results. + try: + rows = paginator.page(page) + except (EmptyPage, InvalidPage): + rows = paginator.page(paginator.num_pages) except: # Exceptions can be swallowed at the template level here, # re-raising as a TemplateSyntaxError makes them visible. diff --git a/horizon/templates/horizon/common/_data_table.html b/horizon/templates/horizon/common/_data_table.html index e64ebf7..3ef33a0 100644 --- a/horizon/templates/horizon/common/_data_table.html +++ b/horizon/templates/horizon/common/_data_table.html @@ -17,7 +17,7 @@ - {% for row in rows %} + {% for row in rows.object_list %} {{ row.render }} {% empty %} @@ -29,6 +29,17 @@ {% blocktrans count counter=rows|length %}Displaying {{ counter }} item{% plural %}Displaying {{ counter }} items{% endblocktrans %} + + {% if rows.has_previous %} + previous + {% endif %} + + Page {{ rows.number }} of {{ rows.paginator.num_pages }} + + {% if rows.has_next %} + next + {% endif %} + {% if table.has_more_data %} | More »