From 20e7ca204e0f007adb9169be11e336038fb7a364 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 18 Oct 2022 09:52:46 -0400 Subject: [PATCH] Enable pagination --- netbox/netbox/forms/__init__.py | 2 +- netbox/netbox/tables/tables.py | 4 +++- netbox/netbox/views/__init__.py | 8 ++++++++ netbox/templates/search.html | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/netbox/netbox/forms/__init__.py b/netbox/netbox/forms/__init__.py index 838a29233..dd1fb7726 100644 --- a/netbox/netbox/forms/__init__.py +++ b/netbox/netbox/forms/__init__.py @@ -21,7 +21,7 @@ class SearchForm(BootstrapMixin, forms.Form): widget=forms.TextInput( attrs={ 'hx-get': '', - 'hx-target': '#search_results', + 'hx-target': '#object_list', 'hx-trigger': 'keyup[target.value.length >= 3] changed delay:500ms', } ) diff --git a/netbox/netbox/tables/tables.py b/netbox/netbox/tables/tables.py index f1d51d63f..3f0c07b68 100644 --- a/netbox/netbox/tables/tables.py +++ b/netbox/netbox/tables/tables.py @@ -197,7 +197,9 @@ class NetBoxTable(BaseTable): class SearchTable(tables.Table): - object_type = columns.ContentTypeColumn() + object_type = columns.ContentTypeColumn( + verbose_name=_('Type') + ) object = tables.Column( linkify=True ) diff --git a/netbox/netbox/views/__init__.py b/netbox/netbox/views/__init__.py index 4a56f82e7..949aa8d79 100644 --- a/netbox/netbox/views/__init__.py +++ b/netbox/netbox/views/__init__.py @@ -11,6 +11,7 @@ from django.template.exceptions import TemplateDoesNotExist from django.views.decorators.csrf import requires_csrf_token from django.views.defaults import ERROR_500_TEMPLATE_NAME, page_not_found from django.views.generic import View +from django_tables2 import RequestConfig from packaging import version from sentry_sdk import capture_message @@ -26,6 +27,7 @@ from netbox.search.backends import search_backend from netbox.tables import SearchTable from tenancy.models import Tenant from utilities.htmx import is_htmx +from utilities.paginator import EnhancedPaginator, get_paginate_count from virtualization.models import Cluster, VirtualMachine from wireless.models import WirelessLAN, WirelessLink @@ -172,6 +174,12 @@ class SearchView(View): table = SearchTable(results) + # Paginate the table results + RequestConfig(request, { + 'paginator_class': EnhancedPaginator, + 'per_page': get_paginate_count(request) + }).configure(table) + # If this is an HTMX request, return only the rendered table HTML if is_htmx(request): return render(request, 'htmx/table.html', { diff --git a/netbox/templates/search.html b/netbox/templates/search.html index 7059e7dc6..e801422c9 100644 --- a/netbox/templates/search.html +++ b/netbox/templates/search.html @@ -30,7 +30,7 @@
-
+
{% include 'htmx/table.html' %}