Enable pagination

This commit is contained in:
jeremystretch 2022-10-18 09:52:46 -04:00
parent 7cc85a609d
commit 20e7ca204e
4 changed files with 13 additions and 3 deletions

View File

@ -21,7 +21,7 @@ class SearchForm(BootstrapMixin, forms.Form):
widget=forms.TextInput( widget=forms.TextInput(
attrs={ attrs={
'hx-get': '', 'hx-get': '',
'hx-target': '#search_results', 'hx-target': '#object_list',
'hx-trigger': 'keyup[target.value.length >= 3] changed delay:500ms', 'hx-trigger': 'keyup[target.value.length >= 3] changed delay:500ms',
} }
) )

View File

@ -197,7 +197,9 @@ class NetBoxTable(BaseTable):
class SearchTable(tables.Table): class SearchTable(tables.Table):
object_type = columns.ContentTypeColumn() object_type = columns.ContentTypeColumn(
verbose_name=_('Type')
)
object = tables.Column( object = tables.Column(
linkify=True linkify=True
) )

View File

@ -11,6 +11,7 @@ from django.template.exceptions import TemplateDoesNotExist
from django.views.decorators.csrf import requires_csrf_token from django.views.decorators.csrf import requires_csrf_token
from django.views.defaults import ERROR_500_TEMPLATE_NAME, page_not_found from django.views.defaults import ERROR_500_TEMPLATE_NAME, page_not_found
from django.views.generic import View from django.views.generic import View
from django_tables2 import RequestConfig
from packaging import version from packaging import version
from sentry_sdk import capture_message from sentry_sdk import capture_message
@ -26,6 +27,7 @@ from netbox.search.backends import search_backend
from netbox.tables import SearchTable from netbox.tables import SearchTable
from tenancy.models import Tenant from tenancy.models import Tenant
from utilities.htmx import is_htmx from utilities.htmx import is_htmx
from utilities.paginator import EnhancedPaginator, get_paginate_count
from virtualization.models import Cluster, VirtualMachine from virtualization.models import Cluster, VirtualMachine
from wireless.models import WirelessLAN, WirelessLink from wireless.models import WirelessLAN, WirelessLink
@ -172,6 +174,12 @@ class SearchView(View):
table = SearchTable(results) 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 this is an HTMX request, return only the rendered table HTML
if is_htmx(request): if is_htmx(request):
return render(request, 'htmx/table.html', { return render(request, 'htmx/table.html', {

View File

@ -30,7 +30,7 @@
</div> </div>
<div class="row px-3"> <div class="row px-3">
<div class="card"> <div class="card">
<div class="card-body" id="search_results"> <div class="card-body" id="object_list">
{% include 'htmx/table.html' %} {% include 'htmx/table.html' %}
</div> </div>
</div> </div>