Closes #6441: Improve UI paginator to optimize page object count

This commit is contained in:
jeremystretch 2021-05-20 12:00:31 -04:00
parent a39522a25e
commit 22927bfc76
2 changed files with 11 additions and 2 deletions

View File

@ -6,6 +6,7 @@
* [#6393](https://github.com/netbox-community/netbox/issues/6393) - Add `description` filter for IP addresses
* [#6400](https://github.com/netbox-community/netbox/issues/6400) - Add cyan color choice for plugin buttons
* [#6441](https://github.com/netbox-community/netbox/issues/6441) - Improve UI paginator to optimize page object count
### Bug Fixes

View File

@ -4,7 +4,9 @@ from django.core.paginator import Paginator, Page
class EnhancedPaginator(Paginator):
def __init__(self, object_list, per_page, **kwargs):
def __init__(self, object_list, per_page, orphans=None, **kwargs):
# Determine the page size
try:
per_page = int(per_page)
if per_page < 1:
@ -12,7 +14,13 @@ class EnhancedPaginator(Paginator):
except ValueError:
per_page = settings.PAGINATE_COUNT
super().__init__(object_list, per_page, **kwargs)
# Set orphans count based on page size
if orphans is None and per_page <= 50:
orphans = 5
elif orphans is None:
orphans = 10
super().__init__(object_list, per_page, orphans=orphans, **kwargs)
def _get_page(self, *args, **kwargs):
return EnhancedPage(*args, **kwargs)