mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
Enable pagination
This commit is contained in:
parent
7cc85a609d
commit
20e7ca204e
@ -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',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -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
|
||||||
)
|
)
|
||||||
|
@ -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', {
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user