1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
Daniel Sheppard e4cb0c3cc2 Fixes #11209 - Fix PrefixIPAddress view with saved sort preferences (#12820)
* Fixes #11209 - Do not add available ips when IPAddressTable sort preferences are saved

* Refine check to account scenario right after clearing ordering string

* Introduce get_table_ordering() utility to determine intended ordering given a request

* Apply fix to VLAN ranges as well

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2023-09-13 10:51:24 -04:00

29 lines
726 B
Python

__all__ = (
'get_table_ordering',
'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):
"""
Render a telephone number as a hyperlink.
"""
if value is None:
return None
return f"tel:{value}"