diff --git a/common/convert.py b/common/convert.py index 6ba29cabb..8964fc3ed 100644 --- a/common/convert.py +++ b/common/convert.py @@ -1,4 +1,5 @@ from datetime import timedelta +from typing import Optional from typing import Tuple from django.core.exceptions import ValidationError @@ -6,7 +7,9 @@ from employees.common.strings import ReportValidationStrings -def timedelta_to_string(data: timedelta) -> str: +def timedelta_to_string(data: Optional[timedelta]) -> str: + if data is None: + return "" days = data.days hours = data.seconds // 3600 minutes = (data.seconds % 3600) // 60 diff --git a/employees/forms.py b/employees/forms.py index c4a1234b3..defe327b5 100644 --- a/employees/forms.py +++ b/employees/forms.py @@ -32,13 +32,13 @@ def __init__(self, queryset: QuerySet, *args: Any, **kwargs: Any) -> None: class DurationInput(TextInput): def format_value(self, value: Optional[str]) -> str: - if value is not None: + if value is not None and value != ":": return timedelta_to_string(parse_duration(value)) return "" class DurationFieldForm(forms.DurationField): - widget = DurationInput + widget = DurationInput(attrs={"data-mask": "09:99", "placeholder": "H:MM"}) def clean(self, value: str) -> str: if value is None: diff --git a/employees/templates/employees/author_report_list.html b/employees/templates/employees/author_report_list.html index b379ca336..4623a6f28 100644 --- a/employees/templates/employees/author_report_list.html +++ b/employees/templates/employees/author_report_list.html @@ -89,6 +89,6 @@