diff --git a/src/argus/htmx/dateformat/constants.py b/src/argus/htmx/dateformat/constants.py index 67de6361f..18d33b7c4 100644 --- a/src/argus/htmx/dateformat/constants.py +++ b/src/argus/htmx/dateformat/constants.py @@ -1,3 +1,4 @@ +import dataclasses from django.conf import settings __all__ = [ @@ -8,12 +9,22 @@ ] +@dataclasses.dataclass +class DateTimeFormat: + datetime: str + date: str + time: str + + DATETIME_FALLBACK = "LOCALE" + +# Datetime format specification can be found here: +# https://docs.djangoproject.com/en/5.1/ref/templates/builtins/#date DATETIME_FORMATS = { - "LOCALE": "DATETIME_FORMAT", # default - "ISO": "Y-m-d H:i:s", - "RFC5322": "r", - "EPOCH": "U", + "LOCALE": DateTimeFormat(datetime="DATETIME_FORMAT", date="DATE_FORMAT", time="TIME_FORMAT"), # default + "ISO": DateTimeFormat(datetime="Y-m-d H:i:s", date="Y-m-d", time="H:i:s"), + "RFC5322": DateTimeFormat("r", "r", "r"), + "EPOCH": DateTimeFormat("U", "U", "U"), } DATETIME_CHOICES = tuple((format, format) for format in DATETIME_FORMATS) diff --git a/src/argus/htmx/user/preferences/models.py b/src/argus/htmx/user/preferences/models.py index 9524c6784..36f8b78be 100644 --- a/src/argus/htmx/user/preferences/models.py +++ b/src/argus/htmx/user/preferences/models.py @@ -41,4 +41,8 @@ class ArgusHtmxPreferences: def update_context(self, context): datetime_format_name = context.get("datetime_format_name", DATETIME_DEFAULT) datetime_format = DATETIME_FORMATS[datetime_format_name] - return {"datetime_format": datetime_format} + return { + "datetime_format": datetime_format.datetime, + "date_format": datetime_format.date, + "time_format": datetime_format.time, + }