Parcourir la source

Fixes #7721: Retain pagination preference when MAX_PAGE_SIZE is zero

jeremystretch il y a 4 ans
Parent
commit
318c8b85e9
2 fichiers modifiés avec 9 ajouts et 3 suppressions
  1. 1 0
      docs/release-notes/version-3.0.md
  2. 8 3
      netbox/utilities/paginator.py

+ 1 - 0
docs/release-notes/version-3.0.md

@@ -19,6 +19,7 @@
 * [#7647](https://github.com/netbox-community/netbox/issues/7647) - Require interface assignment when designating IP address as primary for device/VM during CSV import
 * [#7664](https://github.com/netbox-community/netbox/issues/7664) - Preserve initial form data when bulk edit validation fails
 * [#7717](https://github.com/netbox-community/netbox/issues/7717) - Restore missing tags column on IP range table
+* [#7721](https://github.com/netbox-community/netbox/issues/7721) - Retain pagination preference when `MAX_PAGE_SIZE` is zero
 
 ---
 

+ 8 - 3
netbox/utilities/paginator.py

@@ -57,17 +57,22 @@ def get_paginate_count(request):
 
     Return the lesser of the calculated value and MAX_PAGE_SIZE.
     """
+    def _max_allowed(page_size):
+        if settings.MAX_PAGE_SIZE:
+            return min(page_size, settings.MAX_PAGE_SIZE)
+        return page_size
+
     if 'per_page' in request.GET:
         try:
             per_page = int(request.GET.get('per_page'))
             if request.user.is_authenticated:
                 request.user.config.set('pagination.per_page', per_page, commit=True)
-            return min(per_page, settings.MAX_PAGE_SIZE)
+            return _max_allowed(per_page)
         except ValueError:
             pass
 
     if request.user.is_authenticated:
         per_page = request.user.config.get('pagination.per_page', settings.PAGINATE_COUNT)
-        return min(per_page, settings.MAX_PAGE_SIZE)
+        return _max_allowed(per_page)
 
-    return min(settings.PAGINATE_COUNT, settings.MAX_PAGE_SIZE)
+    return _max_allowed(settings.PAGINATE_COUNT)