Add scheduling for reports and scripts

This commit is contained in:
kkthxbye-code
2022-09-18 15:06:28 +02:00
parent 41d653738a
commit 824b4e0923
7 changed files with 63 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
from django import forms
from utilities.forms import BootstrapMixin
from utilities.forms import BootstrapMixin, DateTimePicker
__all__ = (
'ScriptForm',
@@ -14,17 +14,25 @@ class ScriptForm(BootstrapMixin, forms.Form):
label="Commit changes",
help_text="Commit changes to the database (uncheck for a dry-run)"
)
_schedule_at = forms.DateTimeField(
required=False,
widget=DateTimePicker(),
label="Schedule at",
help_text="Schedule execution of script to a set time",
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Move _commit to the end of the form
# Move _commit and _schedule_at to the end of the form
schedule_at = self.fields.pop('_schedule_at')
commit = self.fields.pop('_commit')
self.fields['_schedule_at'] = schedule_at
self.fields['_commit'] = commit
@property
def requires_input(self):
"""
A boolean indicating whether the form requires user input (ignore the _commit field).
A boolean indicating whether the form requires user input (ignore the _commit and _schedule_at fields).
"""
return bool(len(self.fields) > 1)
return bool(len(self.fields) > 2)