mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 08:25:17 -06:00
Introduce get_table_ordering() utility to determine intended ordering given a request
This commit is contained in:
parent
16c253b2da
commit
70e18021d1
@ -1,7 +1,6 @@
|
|||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db.models import F, Prefetch
|
from django.db.models import F, Prefetch
|
||||||
from django.db.models.expressions import RawSQL
|
from django.db.models.expressions import RawSQL
|
||||||
from django.db.models.functions import Round
|
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
@ -11,6 +10,7 @@ from dcim.filtersets import InterfaceFilterSet
|
|||||||
from dcim.models import Interface, Site
|
from dcim.models import Interface, Site
|
||||||
from netbox.views import generic
|
from netbox.views import generic
|
||||||
from tenancy.views import ObjectContactsView
|
from tenancy.views import ObjectContactsView
|
||||||
|
from utilities.tables import get_table_ordering
|
||||||
from utilities.utils import count_related
|
from utilities.utils import count_related
|
||||||
from utilities.views import ViewTab, register_model_view
|
from utilities.views import ViewTab, register_model_view
|
||||||
from virtualization.filtersets import VMInterfaceFilterSet
|
from virtualization.filtersets import VMInterfaceFilterSet
|
||||||
@ -606,12 +606,7 @@ class PrefixIPAddressesView(generic.ObjectChildrenView):
|
|||||||
return parent.get_child_ips().restrict(request.user, 'view').prefetch_related('vrf', 'tenant', 'tenant__group')
|
return parent.get_child_ips().restrict(request.user, 'view').prefetch_related('vrf', 'tenant', 'tenant__group')
|
||||||
|
|
||||||
def prep_table_data(self, request, queryset, parent):
|
def prep_table_data(self, request, queryset, parent):
|
||||||
# Check for presence of a q string, an ordering string, or user preferences ordering and the ordering string
|
if not get_table_ordering(request, self.table):
|
||||||
# is blank
|
|
||||||
if not request.GET.get('q') and not request.GET.get('sort') and not (
|
|
||||||
request.user.is_authenticated and request.user.config.get(f'tables.IPAddressTable.ordering') and
|
|
||||||
not request.GET.get('sort') == ''
|
|
||||||
):
|
|
||||||
return add_available_ipaddresses(parent.prefix, queryset, parent.is_pool)
|
return add_available_ipaddresses(parent.prefix, queryset, parent.is_pool)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
@ -1,8 +1,24 @@
|
|||||||
__all__ = (
|
__all__ = (
|
||||||
|
'get_table_ordering',
|
||||||
'linkify_phone',
|
'linkify_phone',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_table_ordering(request, table):
|
||||||
|
"""
|
||||||
|
Given a request, return the prescribed table ordering, if any. This may be necessary to determine prior to rendering
|
||||||
|
the table itself.
|
||||||
|
"""
|
||||||
|
# Check for an explicit ordering
|
||||||
|
if 'sort' in request.GET:
|
||||||
|
return request.GET['sort'] or None
|
||||||
|
|
||||||
|
# Check for a configured preference
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
if preference := request.user.config.get(f'tables.{table.__name__}.ordering'):
|
||||||
|
return preference
|
||||||
|
|
||||||
|
|
||||||
def linkify_phone(value):
|
def linkify_phone(value):
|
||||||
"""
|
"""
|
||||||
Render a telephone number as a hyperlink.
|
Render a telephone number as a hyperlink.
|
||||||
|
Loading…
Reference in New Issue
Block a user