Skip to content

Commit f7b02ef

Browse files
author
Shinya Kawabata
committed
Fix pagination of notifications
Pagination of notifications are corrupted by this change: I112725c0e2ef6ceceb2d7be31ed36defa9d77d50 And this patch also fixes page count. Change-Id: I56581d62480f05bd9c1a91b3d37911e720a82f40
1 parent 6463b25 commit f7b02ef

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

monitoring/notifications/views.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from horizon import exceptions
2121
from horizon import forms
2222
from horizon import tables
23+
from horizon.utils import functions as utils
2324

2425
from monitoring.notifications import constants
2526
from monitoring.notifications import forms as notification_forms
@@ -28,7 +29,6 @@
2829

2930
from openstack_dashboard import policy
3031

31-
LIMIT = 10
3232
PREV_PAGE_LIMIT = 100
3333

3434

@@ -44,9 +44,10 @@ def get_data(self):
4444
results = []
4545
if page_offset is None:
4646
page_offset = 0
47+
limit = utils.get_page_size(self.request)
4748
try:
48-
results = api.monitor.notification_list(self.request, page_offset, LIMIT)
49-
paginator = Paginator(results, LIMIT)
49+
results = api.monitor.notification_list(self.request, page_offset, limit)
50+
paginator = Paginator(results, limit)
5051
results = paginator.page(1)
5152
except EmptyPage:
5253
results = paginator.page(paginator.num_pages)
@@ -70,12 +71,16 @@ def get_context_data(self, **kwargs):
7071
if page_offset is None:
7172
page_offset = 0
7273
prev_page_stack = []
74+
else:
75+
page_offset = int(page_offset)
76+
77+
limit = utils.get_page_size(self.request)
7378
try:
7479
# To judge whether there is next page, get LIMIT + 1
7580
results = api.monitor.notification_list(self.request, page_offset,
76-
LIMIT + 1)
81+
limit + 1)
7782
num_results = len(results)
78-
paginator = Paginator(results, LIMIT)
83+
paginator = Paginator(results, limit)
7984
contacts = paginator.page(1)
8085
except EmptyPage:
8186
contacts = paginator.page(paginator.num_pages)
@@ -85,10 +90,10 @@ def get_context_data(self, **kwargs):
8590

8691
context["contacts"] = contacts
8792

88-
if num_results < LIMIT + 1:
93+
if num_results < limit + 1:
8994
context["page_offset"] = None
9095
else:
91-
context["page_offset"] = contacts.object_list[-1]["id"]
96+
context["page_offset"] = page_offset + limit
9297

9398
if page_offset in prev_page_stack:
9499
index = prev_page_stack.index(page_offset)
@@ -100,7 +105,7 @@ def get_context_data(self, **kwargs):
100105

101106
if len(prev_page_stack) > PREV_PAGE_LIMIT:
102107
del prev_page_stack[0]
103-
prev_page_stack.append(str(page_offset))
108+
prev_page_stack.append(page_offset)
104109
self.request.session['prev_page_stack'] = prev_page_stack
105110

106111
return context

0 commit comments

Comments
 (0)