Fixes #2985: Fix pagination page length for rack elevations

This commit is contained in:
Jeremy Stretch 2019-03-11 12:51:03 -04:00
parent f4b85751bb
commit 7e70bfaacc
3 changed files with 11 additions and 3 deletions

View File

@ -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
---

View File

@ -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:

View File

@ -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):