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

40 lines
1.2 KiB
Python

from django_tables2 import RequestConfig
from utilities.paginator import EnhancedPaginator, get_paginate_count
from .columns import *
from .tables import *
def configure_table(table, request):
"""
Paginate a table given a request context.
"""
# Save ordering preference
if request.user.is_authenticated:
table_name = table.__class__.__name__
if table.prefixed_order_by_field in request.GET:
# If an ordering has been specified as a query parameter, save it as the
# user's preferred ordering for this table.
ordering = request.GET.getlist(table.prefixed_order_by_field)
request.user.config.set(f'tables.{table_name}.ordering', ordering, commit=True)
elif ordering := request.user.config.get(f'tables.{table_name}.ordering'):
# If no ordering has been specified, set the preferred ordering (if any).
table.order_by = ordering
# Paginate the table results
paginate = {
'paginator_class': EnhancedPaginator,
'per_page': get_paginate_count(request)
}
RequestConfig(request, paginate).configure(table)
#
# Callables
#
def linkify_phone(value):
if value is None:
return None
return f"tel:{value}"