mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-20 12:22:23 -06:00
Clean up nullable fields declaration for bulk edit forms
This commit is contained in:
@@ -10,7 +10,7 @@ from .widgets import APISelect, APISelectMultiple, ClearableFileInput, StaticSel
|
||||
__all__ = (
|
||||
'BootstrapMixin',
|
||||
'BulkEditForm',
|
||||
'BulkEditBaseForm',
|
||||
'BulkEditMixin',
|
||||
'BulkRenameForm',
|
||||
'ConfirmationForm',
|
||||
'CSVModelForm',
|
||||
@@ -21,6 +21,10 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
#
|
||||
# Mixins
|
||||
#
|
||||
|
||||
class BootstrapMixin:
|
||||
"""
|
||||
Add the base Bootstrap CSS classes to form elements.
|
||||
@@ -61,6 +65,24 @@ class BootstrapMixin:
|
||||
field.widget.attrs['class'] = ' '.join((css, 'form-select')).strip()
|
||||
|
||||
|
||||
class BulkEditMixin:
|
||||
"""
|
||||
Base form for editing multiple objects in bulk
|
||||
"""
|
||||
def __init__(self, model, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.model = model
|
||||
self.nullable_fields = ()
|
||||
|
||||
# Copy any nullable fields defined in Meta
|
||||
if hasattr(self, 'Meta') and hasattr(self.Meta, 'nullable_fields'):
|
||||
self.nullable_fields = self.Meta.nullable_fields
|
||||
|
||||
|
||||
#
|
||||
# Form classes
|
||||
#
|
||||
|
||||
class ReturnURLForm(forms.Form):
|
||||
"""
|
||||
Provides a hidden return URL field to control where the user is directed after the form is submitted.
|
||||
@@ -75,21 +97,7 @@ class ConfirmationForm(BootstrapMixin, ReturnURLForm):
|
||||
confirm = forms.BooleanField(required=True, widget=forms.HiddenInput(), initial=True)
|
||||
|
||||
|
||||
class BulkEditBaseForm(forms.Form):
|
||||
"""
|
||||
Base form for editing multiple objects in bulk
|
||||
"""
|
||||
def __init__(self, model, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.model = model
|
||||
self.nullable_fields = []
|
||||
|
||||
# Copy any nullable fields defined in Meta
|
||||
if hasattr(self.Meta, 'nullable_fields'):
|
||||
self.nullable_fields = self.Meta.nullable_fields
|
||||
|
||||
|
||||
class BulkEditForm(BootstrapMixin, BulkEditBaseForm):
|
||||
class BulkEditForm(BootstrapMixin, BulkEditMixin, forms.Form):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user