mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 19:47:20 -06:00
* Update isotime and isodate filters to be timezone-aware for display in templates (particularly Scripts) * Handle naive datetimes gracefully
This commit is contained in:
parent
dab27695b9
commit
1d2ea90fd4
@ -31,7 +31,7 @@ class ReportForm(forms.Form):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Annotate the current system time for reference
|
# Annotate the current system time for reference
|
||||||
now = local_now().strftime('%Y-%m-%d %H:%M:%S')
|
now = local_now().strftime('%Y-%m-%d %H:%M:%S %Z')
|
||||||
self.fields['schedule_at'].help_text += _(' (current time: <strong>{now}</strong>)').format(now=now)
|
self.fields['schedule_at'].help_text += _(' (current time: <strong>{now}</strong>)').format(now=now)
|
||||||
|
|
||||||
# Remove scheduling fields if scheduling is disabled
|
# Remove scheduling fields if scheduling is disabled
|
||||||
|
@ -37,7 +37,7 @@ class ScriptForm(forms.Form):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Annotate the current system time for reference
|
# Annotate the current system time for reference
|
||||||
now = local_now().strftime('%Y-%m-%d %H:%M:%S')
|
now = local_now().strftime('%Y-%m-%d %H:%M:%S %Z')
|
||||||
self.fields['_schedule_at'].help_text += _(' (current time: <strong>{now}</strong>)').format(now=now)
|
self.fields['_schedule_at'].help_text += _(' (current time: <strong>{now}</strong>)').format(now=now)
|
||||||
|
|
||||||
# Remove scheduling fields if scheduling is disabled
|
# Remove scheduling fields if scheduling is disabled
|
||||||
|
@ -8,6 +8,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from django.contrib.humanize.templatetags.humanize import naturalday, naturaltime
|
from django.contrib.humanize.templatetags.humanize import naturalday, naturaltime
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.utils.timezone import localtime
|
||||||
from markdown import markdown
|
from markdown import markdown
|
||||||
from markdown.extensions.tables import TableExtension
|
from markdown.extensions.tables import TableExtension
|
||||||
|
|
||||||
@ -218,7 +219,8 @@ def isodate(value):
|
|||||||
text = value.isoformat()
|
text = value.isoformat()
|
||||||
return mark_safe(f'<span title="{naturalday(value)}">{text}</span>')
|
return mark_safe(f'<span title="{naturalday(value)}">{text}</span>')
|
||||||
elif type(value) is datetime.datetime:
|
elif type(value) is datetime.datetime:
|
||||||
text = value.date().isoformat()
|
local_value = localtime(value) if value.tzinfo else value
|
||||||
|
text = local_value.date().isoformat()
|
||||||
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')
|
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')
|
||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
@ -229,7 +231,8 @@ def isotime(value, spec='seconds'):
|
|||||||
if type(value) is datetime.time:
|
if type(value) is datetime.time:
|
||||||
return value.isoformat(timespec=spec)
|
return value.isoformat(timespec=spec)
|
||||||
if type(value) is datetime.datetime:
|
if type(value) is datetime.datetime:
|
||||||
return value.time().isoformat(timespec=spec)
|
local_value = localtime(value) if value.tzinfo else value
|
||||||
|
return local_value.time().isoformat(timespec=spec)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user