Просмотр исходного кода

Fixes #2985: Fix pagination page length for rack elevations

Jeremy Stretch 7 лет назад
Родитель
Сommit
7e70bfaacc
3 измененных файлов с 11 добавлено и 3 удалено
  1. 1 0
      CHANGELOG.md
  2. 3 1
      netbox/dcim/views.py
  3. 7 2
      netbox/utilities/paginator.py

+ 1 - 0
CHANGELOG.md

@@ -23,6 +23,7 @@ v2.5.8 (FUTURE)
 * [#2976](https://github.com/digitalocean/netbox/issues/2976) - Add delete button to tag view
 * [#2980](https://github.com/digitalocean/netbox/issues/2980) - Improve rendering time for API docs
 * [#2984](https://github.com/digitalocean/netbox/issues/2984) - Fix logging of unlabeled cable ID on cable deletion
+* [#2985](https://github.com/digitalocean/netbox/issues/2985) - Fix pagination page length for rack elevations
 
 ---
 

+ 3 - 1
netbox/dcim/views.py

@@ -1,5 +1,6 @@
 import re
 
+from django.conf import settings
 from django.contrib import messages
 from django.contrib.auth.mixins import PermissionRequiredMixin
 from django.core.paginator import EmptyPage, PageNotAnInteger
@@ -353,8 +354,9 @@ class RackElevationListView(View):
         total_count = racks.count()
 
         # Pagination
-        paginator = EnhancedPaginator(racks, 25)
+        per_page = request.GET.get('per_page', settings.PAGINATE_COUNT)
         page_number = request.GET.get('page', 1)
+        paginator = EnhancedPaginator(racks, per_page)
         try:
             page = paginator.page(page_number)
         except PageNotAnInteger:

+ 7 - 2
netbox/utilities/paginator.py

@@ -5,8 +5,13 @@ from django.core.paginator import Paginator, Page
 class EnhancedPaginator(Paginator):
 
     def __init__(self, object_list, per_page, **kwargs):
-        if not isinstance(per_page, int) or per_page < 1:
-            per_page = getattr(settings, 'PAGINATE_COUNT', 50)
+        try:
+            per_page = int(per_page)
+            if per_page < 1:
+                per_page = settings.PAGINATE_COUNT
+        except ValueError:
+            per_page = settings.PAGINATE_COUNT
+
         super().__init__(object_list, per_page, **kwargs)
 
     def _get_page(self, *args, **kwargs):