scripts.py 763 B

123456789101112131415161718192021222324252627282930
  1. from django import forms
  2. from utilities.forms import BootstrapMixin
  3. __all__ = (
  4. 'ScriptForm',
  5. )
  6. class ScriptForm(BootstrapMixin, forms.Form):
  7. _commit = forms.BooleanField(
  8. required=False,
  9. initial=True,
  10. label="Commit changes",
  11. help_text="Commit changes to the database (uncheck for a dry-run)"
  12. )
  13. def __init__(self, *args, **kwargs):
  14. super().__init__(*args, **kwargs)
  15. # Move _commit to the end of the form
  16. commit = self.fields.pop('_commit')
  17. self.fields['_commit'] = commit
  18. @property
  19. def requires_input(self):
  20. """
  21. A boolean indicating whether the form requires user input (ignore the _commit field).
  22. """
  23. return bool(len(self.fields) > 1)