Fixes #11384: Correct current time display on script & report forms

This commit is contained in:
jeremystretch 2023-01-06 09:42:13 -05:00
parent b88fcb6625
commit 0669fda1fd
4 changed files with 14 additions and 3 deletions

View File

@ -11,6 +11,7 @@
### Bug Fixes
* [#11384](https://github.com/netbox-community/netbox/issues/11384) - Correct current time display on script & report forms
* [#11403](https://github.com/netbox-community/netbox/issues/11403) - Fix exception when scheduling a job in the past
---

View File

@ -3,6 +3,7 @@ from django.utils import timezone
from django.utils.translation import gettext as _
from utilities.forms import BootstrapMixin, DateTimePicker, SelectDurationWidget
from utilities.utils import local_now
__all__ = (
'ReportForm',
@ -35,5 +36,5 @@ class ReportForm(BootstrapMixin, forms.Form):
super().__init__(*args, **kwargs)
# Annotate the current system time for reference
now = timezone.now().strftime('%Y-%m-%d %H:%M:%S')
now = local_now().strftime('%Y-%m-%d %H:%M:%S')
self.fields['schedule_at'].help_text += f' (current time: <strong>{now}</strong>)'

View File

@ -1,8 +1,8 @@
from django import forms
from django.utils import timezone
from django.utils.translation import gettext as _
from utilities.forms import BootstrapMixin, DateTimePicker, SelectDurationWidget
from utilities.utils import local_now
__all__ = (
'ScriptForm',
@ -34,7 +34,7 @@ class ScriptForm(BootstrapMixin, forms.Form):
super().__init__(*args, **kwargs)
# Annotate the current system time for reference
now = timezone.now().strftime('%Y-%m-%d %H:%M:%S')
now = local_now().strftime('%Y-%m-%d %H:%M:%S')
self.fields['_schedule_at'].help_text += f' (current time: <strong>{now}</strong>)'
# Move _commit and _schedule_at to the end of the form

View File

@ -12,6 +12,8 @@ from django.db.models import Count, OuterRef, Subquery
from django.db.models.functions import Coalesce
from django.http import QueryDict
from django.utils.html import escape
from django.utils import timezone
from django.utils.timezone import localtime
from jinja2.sandbox import SandboxedEnvironment
from mptt.models import MPTTModel
@ -527,3 +529,10 @@ def highlight_string(value, highlight, trim_pre=None, trim_post=None, trim_place
post = post[:trim_post] + trim_placeholder
return f'{escape(pre)}<mark>{escape(match)}</mark>{escape(post)}'
def local_now():
"""
Return the current date & time in the system timezone.
"""
return localtime(timezone.now())