mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Enable scheduling_enabled parameter for reports
This commit is contained in:
committed by
Jeremy Stretch
parent
197c6a1cbf
commit
b167153186
@@ -25,20 +25,25 @@ class ReportForm(BootstrapMixin, forms.Form):
|
||||
help_text=_("Interval at which this report is re-run (in minutes)")
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
scheduled_time = self.cleaned_data['schedule_at']
|
||||
if scheduled_time and scheduled_time < local_now():
|
||||
raise forms.ValidationError(_('Scheduled time must be in the future.'))
|
||||
|
||||
# When interval is used without schedule at, raise an exception
|
||||
if self.cleaned_data['interval'] and not scheduled_time:
|
||||
self.cleaned_data['schedule_at'] = local_now()
|
||||
|
||||
return self.cleaned_data
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, *args, scheduling_enabled=True, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Annotate the current system time for reference
|
||||
now = local_now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
self.fields['schedule_at'].help_text += f' (current time: <strong>{now}</strong>)'
|
||||
|
||||
# Remove scheduling fields if scheduling is disabled
|
||||
if not scheduling_enabled:
|
||||
self.fields.pop('schedule_at')
|
||||
self.fields.pop('interval')
|
||||
|
||||
def clean(self):
|
||||
scheduled_time = self.cleaned_data.get('schedule_at')
|
||||
if scheduled_time and scheduled_time < local_now():
|
||||
raise forms.ValidationError(_('Scheduled time must be in the future.'))
|
||||
|
||||
# When interval is used without schedule at, schedule for the current time
|
||||
if self.cleaned_data.get('interval') and not scheduled_time:
|
||||
self.cleaned_data['schedule_at'] = local_now()
|
||||
|
||||
return self.cleaned_data
|
||||
|
@@ -44,12 +44,12 @@ class ScriptForm(BootstrapMixin, forms.Form):
|
||||
self.fields.pop('_interval')
|
||||
|
||||
def clean(self):
|
||||
scheduled_time = self.cleaned_data['_schedule_at']
|
||||
scheduled_time = self.cleaned_data.get('_schedule_at')
|
||||
if scheduled_time and scheduled_time < local_now():
|
||||
raise forms.ValidationError(_('Scheduled time must be in the future.'))
|
||||
|
||||
# When interval is used without schedule at, schedule for the current time
|
||||
if self.cleaned_data['_interval'] and not scheduled_time:
|
||||
if self.cleaned_data.get('_interval') and not scheduled_time:
|
||||
self.cleaned_data['_schedule_at'] = local_now()
|
||||
|
||||
return self.cleaned_data
|
||||
|
Reference in New Issue
Block a user