Browse Source

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
Pengju Jiao 1 year ago
parent
commit
1d7fd7c754
2 changed files with 17 additions and 10 deletions
  1. 16
    9
      karbor_dashboard/api/karbor.py
  2. 1
    1
      karbor_dashboard/checkpoints/views.py

+ 16
- 9
karbor_dashboard/api/karbor.py View File

@@ -54,6 +54,19 @@ def karborclient(request):
54 54
 
55 55
 def update_pagination(entities, page_size, marker, sort_dir, sort_key,
56 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
+
69
+def get_pagination_info(entities, page_size, marker, reversed_order):
57 70
     has_more_data = has_prev_data = False
58 71
     if len(entities) > page_size:
59 72
         has_more_data = True
@@ -66,13 +79,6 @@ def update_pagination(entities, page_size, marker, sort_dir, sort_key,
66 79
     # last page condition
67 80
     elif marker is not None:
68 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 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 415
             sort_key=sort_key,
410 416
             sort_dir=sort_dir,
411 417
             sort=sort)
412
-        checkpoints, has_more_data, has_prev_data = update_pagination(
413
-            checkpoints, page_size, marker, sort_dir, sort_key, reversed_order)
418
+        checkpoints, has_more_data, has_prev_data = \
419
+            get_pagination_info(
420
+                checkpoints, page_size, marker, reversed_order)
414 421
     else:
415 422
         checkpoints = karborclient(request).checkpoints.list(
416 423
             provider_id=provider_id,

+ 1
- 1
karbor_dashboard/checkpoints/views.py View File

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

Loading…
Cancel
Save