From 9172a7ba0b150042d286702e1c339f3a6b6c7793 Mon Sep 17 00:00:00 2001 From: Nicolas Simonds Date: Tue, 7 May 2013 18:58:53 -0700 Subject: [PATCH] Make pagination tunable through the settings panel This patch set expands on the fine work done in https://review.openstack.org/26022 It makes the number of items displayed a per-user tunable through the "Settings" panel and a session cookie, with the default/max values being the values set in django.conf.settings Fixes Bug: 1046915 Change-Id: I38ef4845d46bce62e44209865885aff8eb0bac83 --- openstack_dashboard/api/nova.py | 7 ++++++- openstack_dashboard/dashboards/settings/user/forms.py | 9 +++++++++ openstack_dashboard/dashboards/settings/user/views.py | 6 +++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/openstack_dashboard/api/nova.py b/openstack_dashboard/api/nova.py index e02c9fa22bf..b213fa91563 100644 --- a/openstack_dashboard/api/nova.py +++ b/openstack_dashboard/api/nova.py @@ -362,7 +362,9 @@ def server_get(request, instance_id): def server_list(request, search_opts=None, all_tenants=False): - page_size = getattr(settings, 'API_RESULT_PAGE_SIZE', 20) + page_size = request.session.get('horizon_pagesize', + getattr(settings, 'API_RESULT_PAGE_SIZE', + 20)) paginate = False if search_opts is None: search_opts = {} @@ -382,6 +384,9 @@ def server_list(request, search_opts=None, all_tenants=False): if paginate and len(servers) > page_size: servers.pop(-1) has_more_data = True + elif paginate and len(servers) == getattr(settings, 'API_RESULT_LIMIT', + 1000): + has_more_data = True return (servers, has_more_data) diff --git a/openstack_dashboard/dashboards/settings/user/forms.py b/openstack_dashboard/dashboards/settings/user/forms.py index 059f8940803..bb0b385d4d3 100644 --- a/openstack_dashboard/dashboards/settings/user/forms.py +++ b/openstack_dashboard/dashboards/settings/user/forms.py @@ -28,6 +28,13 @@ class UserSettingsForm(forms.SelfHandlingForm): language = forms.ChoiceField() timezone = forms.ChoiceField() + pagesize = forms.IntegerField(label=translation.ugettext("Items Per Page"), + min_value=1, + max_value=getattr(settings, + 'API_RESULT_LIMIT', + 1000), + help_text=translation.ugettext( + "Number of items to show per page")) def __init__(self, *args, **kwargs): super(UserSettingsForm, self).__init__(*args, **kwargs) @@ -70,6 +77,8 @@ def handle(self, request, data): request.session['django_timezone'] = pytz.timezone( data['timezone']).zone + request.session['horizon_pagesize'] = data['pagesize'] + messages.success(request, translation.ugettext("Settings saved.")) return response diff --git a/openstack_dashboard/dashboards/settings/user/views.py b/openstack_dashboard/dashboards/settings/user/views.py index faa2c4abb00..67d543134ee 100644 --- a/openstack_dashboard/dashboards/settings/user/views.py +++ b/openstack_dashboard/dashboards/settings/user/views.py @@ -14,6 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. +from django.conf import settings from horizon import forms from .forms import UserSettingsForm @@ -25,7 +26,10 @@ class UserSettingsView(forms.ModalFormView): def get_initial(self): return {'language': self.request.LANGUAGE_CODE, - 'timezone': self.request.session.get('django_timezone', 'UTC')} + 'timezone': self.request.session.get('django_timezone', 'UTC'), + 'pagesize': self.request.session.get( + 'horizon_pagesize', + getattr(settings, 'API_RESULT_PAGE_SIZE', 20))} def form_valid(self, form): return form.handle(self.request, form.cleaned_data)