Fixes #22441: Address claudebot review feedback
- humanize_duration: guard on 'is None' instead of falsiness so timedelta(0) renders as '0s' rather than blank - execution_time filter: add label= for consistency with sibling filters
This commit is contained in:
parent
e7e1362c35
commit
f1f84faa7f
|
|
@ -132,7 +132,9 @@ class JobFilterSet(BaseFilterSet):
|
|||
field_name='completed',
|
||||
lookup_expr='gte'
|
||||
)
|
||||
execution_time = django_filters.DurationFilter()
|
||||
execution_time = django_filters.DurationFilter(
|
||||
label=_('Execution time')
|
||||
)
|
||||
execution_time__gte = django_filters.DurationFilter(
|
||||
field_name='execution_time',
|
||||
lookup_expr='gte',
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ __all__ = (
|
|||
def humanize_duration(value):
|
||||
"""
|
||||
Express a timedelta in a human-friendly format. Example: 1h 5m 23s. Returns an empty string
|
||||
for a null or zero-length duration.
|
||||
for None; zero-duration timedeltas render as "0s".
|
||||
"""
|
||||
if not value:
|
||||
if value is None:
|
||||
return ''
|
||||
|
||||
# Round to whole seconds and decompose
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@ from utilities.string import humanize_duration
|
|||
|
||||
class HumanizeDurationTest(TestCase):
|
||||
|
||||
def test_none_and_zero(self):
|
||||
def test_none(self):
|
||||
self.assertEqual(humanize_duration(None), '')
|
||||
self.assertEqual(humanize_duration(timedelta(0)), '')
|
||||
|
||||
def test_zero_duration(self):
|
||||
self.assertEqual(humanize_duration(timedelta(0)), '0s')
|
||||
|
||||
def test_seconds_only(self):
|
||||
self.assertEqual(humanize_duration(timedelta(seconds=45)), '45s')
|
||||
|
|
|
|||
Loading…
Reference in New Issue