1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

40 lines
1.1 KiB
Python
Raw Normal View History

2021-09-28 10:44:53 -04:00
from django import forms
from django.utils.translation import gettext as _
2021-09-28 10:44:53 -04:00
2022-09-18 15:06:28 +02:00
from utilities.forms import BootstrapMixin, DateTimePicker
2021-09-28 10:44:53 -04:00
__all__ = (
'ScriptForm',
)
class ScriptForm(BootstrapMixin, forms.Form):
_commit = forms.BooleanField(
required=False,
initial=True,
label=_("Commit changes"),
help_text=_("Commit changes to the database (uncheck for a dry-run)")
2021-09-28 10:44:53 -04:00
)
2022-09-18 15:06:28 +02:00
_schedule_at = forms.DateTimeField(
required=False,
widget=DateTimePicker(),
label=_("Schedule at"),
help_text=_("Schedule execution of script to a set time"),
2022-09-18 15:06:28 +02:00
)
2021-09-28 10:44:53 -04:00
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
2022-09-18 15:06:28 +02:00
# Move _commit and _schedule_at to the end of the form
schedule_at = self.fields.pop('_schedule_at')
2021-09-28 10:44:53 -04:00
commit = self.fields.pop('_commit')
2022-09-18 15:06:28 +02:00
self.fields['_schedule_at'] = schedule_at
2021-09-28 10:44:53 -04:00
self.fields['_commit'] = commit
@property
def requires_input(self):
"""
2022-09-18 15:06:28 +02:00
A boolean indicating whether the form requires user input (ignore the _commit and _schedule_at fields).
2021-09-28 10:44:53 -04:00
"""
2022-09-18 15:06:28 +02:00
return bool(len(self.fields) > 2)