From b2360b62b51aa4965830b6b19b295a0a9ec79c2f Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 14 Jun 2024 10:38:09 -0400 Subject: [PATCH] Fixes #13925: Support 'zulu' style timestamps for custom fields --- netbox/extras/models/customfields.py | 4 ++++ netbox/utilities/templates/builtins/customfield_value.html | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/netbox/extras/models/customfields.py b/netbox/extras/models/customfields.py index 974affb2e..240998146 100644 --- a/netbox/extras/models/customfields.py +++ b/netbox/extras/models/customfields.py @@ -660,6 +660,10 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel): # Validate date & time elif self.type == CustomFieldTypeChoices.TYPE_DATETIME: if type(value) is not datetime: + # Work around UTC issue for Python < 3.11; see + # https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat + if type(value) is str and value.endswith('Z'): + value = f'{value[:-1]}+00:00' try: datetime.fromisoformat(value) except ValueError: diff --git a/netbox/utilities/templates/builtins/customfield_value.html b/netbox/utilities/templates/builtins/customfield_value.html index 462e62b86..dbf10e1bf 100644 --- a/netbox/utilities/templates/builtins/customfield_value.html +++ b/netbox/utilities/templates/builtins/customfield_value.html @@ -11,7 +11,7 @@ {% elif customfield.type == 'date' and value %} {{ value|isodate }} {% elif customfield.type == 'datetime' and value %} - {{ value|isodate }} {{ value|isodatetime }} + {{ value|isodatetime }} {% elif customfield.type == 'url' and value %} {{ value|truncatechars:70 }} {% elif customfield.type == 'json' and value %}