summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPengju Jiao <jiaopengju@cmss.chinamobile.com>2017-09-05 10:25:10 +0800
committerPengju Jiao <jiaopengju@cmss.chinamobile.com>2017-09-05 10:31:01 +0800
commit1d7fd7c754c48f39534984d1792698f2dce17e10 (patch)
treea21eec3411e4ff01c743f07baba115d91ce33bd8
parentf2f7e6f99bad7112a3682dd191374c75e2e9fc3d (diff)
Fix checkpoints pagination error
Currently, previous page in checkpoints pagination not work, it always throw an error in the web page. It is because that checkpoints in karbor do not need reverse the order (checkpoints are sorted by 'timestamp@id' in the backend, so we can not do the reverse only be the id or name) This patch will fix it. Change-Id: I45c3e7337bf2ee9d3f2fbf9ee7a438884b8b8ca9 Closes-Bug: #1714909
Notes
Notes (review): Code-Review+1: xiangxinyong <xiangxinyong@huawei.com> Code-Review+2: chenying <ying.chen@huawei.com> Code-Review+2: Yuval Brik <yuval@brik.org.il> Workflow+1: Yuval Brik <yuval@brik.org.il> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 05 Sep 2017 06:53:40 +0000 Reviewed-on: https://review.openstack.org/500656 Project: openstack/karbor-dashboard Branch: refs/heads/master
-rw-r--r--karbor_dashboard/api/karbor.py25
-rw-r--r--karbor_dashboard/checkpoints/views.py2
2 files changed, 17 insertions, 10 deletions
diff --git a/karbor_dashboard/api/karbor.py b/karbor_dashboard/api/karbor.py
index 5f2423c..4d273d8 100644
--- a/karbor_dashboard/api/karbor.py
+++ b/karbor_dashboard/api/karbor.py
@@ -54,6 +54,19 @@ def karborclient(request):
54 54
55def update_pagination(entities, page_size, marker, sort_dir, sort_key, 55def update_pagination(entities, page_size, marker, sort_dir, sort_key,
56 reversed_order): 56 reversed_order):
57 entities, has_more_data, has_prev_data = get_pagination_info(
58 entities, page_size, marker, reversed_order)
59
60 # restore the original ordering here
61 if reversed_order:
62 entities = sorted(entities, key=lambda entity:
63 (getattr(entity, sort_key) or '').lower(),
64 reverse=(sort_dir == 'asc'))
65
66 return entities, has_more_data, has_prev_data
67
68
69def get_pagination_info(entities, page_size, marker, reversed_order):
57 has_more_data = has_prev_data = False 70 has_more_data = has_prev_data = False
58 if len(entities) > page_size: 71 if len(entities) > page_size:
59 has_more_data = True 72 has_more_data = True
@@ -66,13 +79,6 @@ def update_pagination(entities, page_size, marker, sort_dir, sort_key,
66 # last page condition 79 # last page condition
67 elif marker is not None: 80 elif marker is not None:
68 has_prev_data = True 81 has_prev_data = True
69
70 # restore the original ordering here
71 if reversed_order:
72 entities = sorted(entities, key=lambda entity:
73 (getattr(entity, sort_key) or '').lower(),
74 reverse=(sort_dir == 'asc'))
75
76 return entities, has_more_data, has_prev_data 82 return entities, has_more_data, has_prev_data
77 83
78 84
@@ -409,8 +415,9 @@ def checkpoint_list_paged(request, provider_id=None, search_opts=None,
409 sort_key=sort_key, 415 sort_key=sort_key,
410 sort_dir=sort_dir, 416 sort_dir=sort_dir,
411 sort=sort) 417 sort=sort)
412 checkpoints, has_more_data, has_prev_data = update_pagination( 418 checkpoints, has_more_data, has_prev_data = \
413 checkpoints, page_size, marker, sort_dir, sort_key, reversed_order) 419 get_pagination_info(
420 checkpoints, page_size, marker, reversed_order)
414 else: 421 else:
415 checkpoints = karborclient(request).checkpoints.list( 422 checkpoints = karborclient(request).checkpoints.list(
416 provider_id=provider_id, 423 provider_id=provider_id,
diff --git a/karbor_dashboard/checkpoints/views.py b/karbor_dashboard/checkpoints/views.py
index 9315d39..8239b15 100644
--- a/karbor_dashboard/checkpoints/views.py
+++ b/karbor_dashboard/checkpoints/views.py
@@ -159,7 +159,7 @@ class IndexView(horizon_tables.DataTableView):
159 marker=marker, 159 marker=marker,
160 paginate=True, 160 paginate=True,
161 sort_dir='asc', 161 sort_dir='asc',
162 sort_key='name', 162 sort_key='id',
163 reversed_order=reversed_order) 163 reversed_order=reversed_order)
164 provider = karborclient.provider_get(self.request, provider_id) 164 provider = karborclient.provider_get(self.request, provider_id)
165 for checkpoint in checkpoints: 165 for checkpoint in checkpoints: