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
This commit is contained in:
Pengju Jiao 2017-09-05 10:25:10 +08:00
parent f2f7e6f99b
commit 1d7fd7c754
2 changed files with 17 additions and 10 deletions

View File

@ -54,6 +54,19 @@ def karborclient(request):
def update_pagination(entities, page_size, marker, sort_dir, sort_key,
reversed_order):
entities, has_more_data, has_prev_data = get_pagination_info(
entities, page_size, marker, reversed_order)
# restore the original ordering here
if reversed_order:
entities = sorted(entities, key=lambda entity:
(getattr(entity, sort_key) or '').lower(),
reverse=(sort_dir == 'asc'))
return entities, has_more_data, has_prev_data
def get_pagination_info(entities, page_size, marker, reversed_order):
has_more_data = has_prev_data = False
if len(entities) > page_size:
has_more_data = True
@ -66,13 +79,6 @@ def update_pagination(entities, page_size, marker, sort_dir, sort_key,
# last page condition
elif marker is not None:
has_prev_data = True
# restore the original ordering here
if reversed_order:
entities = sorted(entities, key=lambda entity:
(getattr(entity, sort_key) or '').lower(),
reverse=(sort_dir == 'asc'))
return entities, has_more_data, has_prev_data
@ -409,8 +415,9 @@ def checkpoint_list_paged(request, provider_id=None, search_opts=None,
sort_key=sort_key,
sort_dir=sort_dir,
sort=sort)
checkpoints, has_more_data, has_prev_data = update_pagination(
checkpoints, page_size, marker, sort_dir, sort_key, reversed_order)
checkpoints, has_more_data, has_prev_data = \
get_pagination_info(
checkpoints, page_size, marker, reversed_order)
else:
checkpoints = karborclient(request).checkpoints.list(
provider_id=provider_id,

View File

@ -159,7 +159,7 @@ class IndexView(horizon_tables.DataTableView):
marker=marker,
paginate=True,
sort_dir='asc',
sort_key='name',
sort_key='id',
reversed_order=reversed_order)
provider = karborclient.provider_get(self.request, provider_id)
for checkpoint in checkpoints: