Jelajahi Sumber

Fixes #13925: Support 'zulu' style timestamps for custom fields

Jeremy Stretch 1 tahun lalu
induk
melakukan
b2360b62b5

+ 4 - 0
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:

+ 1 - 1
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 %}
   <a href="{{ value }}">{{ value|truncatechars:70 }}</a>
 {% elif customfield.type == 'json' and value %}