Skip to content

Commit

Permalink
Make pagination tunable through the settings panel
Browse files Browse the repository at this point in the history
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
  • Loading branch information
0xDEC0DE committed May 8, 2013
1 parent ff573da commit 9172a7b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion openstack_dashboard/api/nova.py
Expand Up @@ -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 = {}
Expand All @@ -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)


Expand Down
9 changes: 9 additions & 0 deletions openstack_dashboard/dashboards/settings/user/forms.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion openstack_dashboard/dashboards/settings/user/views.py
Expand Up @@ -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
Expand All @@ -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)

0 comments on commit 9172a7b

Please sign in to comment.