|
@@ -17,6 +17,7 @@ from netbox.ui.attrs import (
|
|
|
)
|
|
)
|
|
|
from utilities.forms import TableConfigForm, get_selected_values
|
|
from utilities.forms import TableConfigForm, get_selected_values
|
|
|
from utilities.forms.mixins import FORM_FIELD_LOOKUPS
|
|
from utilities.forms.mixins import FORM_FIELD_LOOKUPS
|
|
|
|
|
+from utilities.string import humanize_duration
|
|
|
from utilities.views import get_action_url, get_viewname
|
|
from utilities.views import get_action_url, get_viewname
|
|
|
|
|
|
|
|
__all__ = (
|
|
__all__ = (
|
|
@@ -31,6 +32,7 @@ __all__ = (
|
|
|
'get_item',
|
|
'get_item',
|
|
|
'get_key',
|
|
'get_key',
|
|
|
'humanize_disk_capacity',
|
|
'humanize_disk_capacity',
|
|
|
|
|
+ 'humanize_duration_filter',
|
|
|
'humanize_ram_capacity',
|
|
'humanize_ram_capacity',
|
|
|
'humanize_speed',
|
|
'humanize_speed',
|
|
|
'icon_from_status',
|
|
'icon_from_status',
|
|
@@ -211,6 +213,21 @@ def _format_speed(speed, divisor, unit):
|
|
|
return f'{whole}.{fraction} {unit}'
|
|
return f'{whole}.{fraction} {unit}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+@register.filter('humanize_duration')
|
|
|
|
|
+def humanize_duration_filter(value):
|
|
|
|
|
+ """
|
|
|
|
|
+ Express a timedelta in a human-friendly format, always using the largest appropriate units.
|
|
|
|
|
+ Sub-second durations are rendered with millisecond precision.
|
|
|
|
|
+
|
|
|
|
|
+ Examples:
|
|
|
|
|
+
|
|
|
|
|
+ timedelta(seconds=90) => "1m 30s"
|
|
|
|
|
+ timedelta(hours=1, minutes=5, seconds=23) => "1h 5m 23s"
|
|
|
|
|
+ timedelta(milliseconds=430) => "0.43s"
|
|
|
|
|
+ """
|
|
|
|
|
+ return humanize_duration(value)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@register.filter()
|
|
@register.filter()
|
|
|
def humanize_speed(speed):
|
|
def humanize_speed(speed):
|
|
|
"""
|
|
"""
|