Add background_job toggle to BulkEditForm

This commit is contained in:
Jeremy Stretch 2025-07-16 13:35:55 -04:00
parent 5f8a4f6c43
commit ecdd4bf076
3 changed files with 15 additions and 7 deletions

View File

@ -8,7 +8,7 @@ from django.utils.translation import gettext_lazy as _
from core.models import ObjectType from core.models import ObjectType
from extras.choices import * from extras.choices import *
from extras.models import CustomField, Tag from extras.models import CustomField, Tag
from utilities.forms import CSVModelForm from utilities.forms import BulkEditForm, CSVModelForm
from utilities.forms.fields import CSVModelMultipleChoiceField, DynamicModelMultipleChoiceField from utilities.forms.fields import CSVModelMultipleChoiceField, DynamicModelMultipleChoiceField
from utilities.forms.mixins import CheckLastUpdatedMixin from utilities.forms.mixins import CheckLastUpdatedMixin
from .mixins import CustomFieldsMixin, SavedFiltersMixin, TagsMixin from .mixins import CustomFieldsMixin, SavedFiltersMixin, TagsMixin
@ -100,7 +100,7 @@ class NetBoxModelImportForm(CSVModelForm, NetBoxModelForm):
return customfield.to_form_field(for_csv_import=True) return customfield.to_form_field(for_csv_import=True)
class NetBoxModelBulkEditForm(CustomFieldsMixin, forms.Form): class NetBoxModelBulkEditForm(CustomFieldsMixin, BulkEditForm):
""" """
Base form for modifying multiple NetBox objects (of the same type) in bulk via the UI. Adds support for custom Base form for modifying multiple NetBox objects (of the same type) in bulk via the UI. Adds support for custom
fields and adding/removing tags. fields and adding/removing tags.
@ -108,9 +108,8 @@ class NetBoxModelBulkEditForm(CustomFieldsMixin, forms.Form):
Attributes: Attributes:
fieldsets: An iterable of two-tuples which define a heading and field set to display per section of fieldsets: An iterable of two-tuples which define a heading and field set to display per section of
the rendered form (optional). If not defined, the all fields will be rendered as a single section. the rendered form (optional). If not defined, the all fields will be rendered as a single section.
nullable_fields: A list of field names indicating which fields support being set to null/empty
""" """
nullable_fields = () fieldsets = None
pk = forms.ModelMultipleChoiceField( pk = forms.ModelMultipleChoiceField(
queryset=None, # Set from self.model on init queryset=None, # Set from self.model on init

View File

@ -17,7 +17,7 @@ __all__ = (
) )
class UserBulkEditForm(forms.Form): class UserBulkEditForm(BulkEditForm):
pk = forms.ModelMultipleChoiceField( pk = forms.ModelMultipleChoiceField(
queryset=User.objects.all(), queryset=User.objects.all(),
widget=forms.MultipleHiddenInput widget=forms.MultipleHiddenInput
@ -55,7 +55,7 @@ class UserBulkEditForm(forms.Form):
nullable_fields = ('first_name', 'last_name') nullable_fields = ('first_name', 'last_name')
class GroupBulkEditForm(forms.Form): class GroupBulkEditForm(BulkEditForm):
pk = forms.ModelMultipleChoiceField( pk = forms.ModelMultipleChoiceField(
queryset=Group.objects.all(), queryset=Group.objects.all(),
widget=forms.MultipleHiddenInput widget=forms.MultipleHiddenInput
@ -73,7 +73,7 @@ class GroupBulkEditForm(forms.Form):
nullable_fields = ('description',) nullable_fields = ('description',)
class ObjectPermissionBulkEditForm(forms.Form): class ObjectPermissionBulkEditForm(BulkEditForm):
pk = forms.ModelMultipleChoiceField( pk = forms.ModelMultipleChoiceField(
queryset=ObjectPermission.objects.all(), queryset=ObjectPermission.objects.all(),
widget=forms.MultipleHiddenInput widget=forms.MultipleHiddenInput

View File

@ -31,9 +31,18 @@ class ConfirmationForm(forms.Form):
class BulkEditForm(forms.Form): class BulkEditForm(forms.Form):
""" """
Provides bulk edit support for objects. Provides bulk edit support for objects.
Attributes:
nullable_fields: A list of field names indicating which fields support being set to null/empty
""" """
nullable_fields = () nullable_fields = ()
background_job = forms.BooleanField(
label=_('Background job'),
help_text=_("Process as a job to edit objects in the background"),
required=False,
)
class BulkRenameForm(forms.Form): class BulkRenameForm(forms.Form):
""" """