2023-04-14 10:33:53 -04:00
|
|
|
__all__ = (
|
2023-09-13 09:51:24 -05:00
|
|
|
'get_table_ordering',
|
2023-04-14 10:33:53 -04:00
|
|
|
'linkify_phone',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-09-13 09:51:24 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-01-27 15:00:10 -05:00
|
|
|
def linkify_phone(value):
|
|
|
|
"""
|
|
|
|
Render a telephone number as a hyperlink.
|
|
|
|
"""
|
|
|
|
if value is None:
|
|
|
|
return None
|
|
|
|
return f"tel:{value}"
|