1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Introduce paginate_table() utility to simplify table pagination

This commit is contained in:
Jeremy Stretch
2021-03-26 13:02:55 -04:00
parent 65d90aa8a3
commit bb00f2ff46
5 changed files with 34 additions and 82 deletions

View File

@ -5,8 +5,11 @@ from django.core.exceptions import FieldDoesNotExist
from django.db.models.fields.related import RelatedField
from django.urls import reverse
from django.utils.safestring import mark_safe
from django_tables2 import RequestConfig
from django_tables2.data import TableQuerysetData
from .paginator import EnhancedPaginator, get_paginate_count
class BaseTable(tables.Table):
"""
@ -331,3 +334,18 @@ class UtilizationColumn(tables.TemplateColumn):
def value(self, value):
return f'{value}%'
#
# Pagination
#
def paginate_table(table, request):
"""
Paginate a table given a request context.
"""
paginate = {
'paginator_class': EnhancedPaginator,
'per_page': get_paginate_count(request)
}
RequestConfig(request, paginate).configure(table)