mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Move background_job field to a mixin
This commit is contained in:
parent
76e0ee837b
commit
f0a3f6462f
@ -2,7 +2,6 @@ import logging
|
||||
import re
|
||||
from copy import deepcopy
|
||||
|
||||
from django import forms
|
||||
from django.contrib import messages
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRel
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
@ -28,6 +27,7 @@ from utilities.exceptions import AbortRequest, AbortTransaction, PermissionsViol
|
||||
from utilities.export import TableExport
|
||||
from utilities.forms import BulkRenameForm, ConfirmationForm, restrict_form_fields
|
||||
from utilities.forms.bulk_import import BulkImportForm
|
||||
from utilities.forms.mixins import BackgroundJobMixin
|
||||
from utilities.htmx import htmx_partial
|
||||
from utilities.jobs import AsyncJobData, is_background_request, process_request_as_job
|
||||
from utilities.permissions import get_permission_for_model
|
||||
@ -892,13 +892,8 @@ class BulkDeleteView(GetReturnURLMixin, BaseMultiObjectView):
|
||||
"""
|
||||
Provide a standard bulk delete form if none has been specified for the view
|
||||
"""
|
||||
class BulkDeleteForm(ConfirmationForm):
|
||||
class BulkDeleteForm(BackgroundJobMixin, ConfirmationForm):
|
||||
pk = ModelMultipleChoiceField(queryset=self.queryset, widget=MultipleHiddenInput)
|
||||
background_job = forms.BooleanField(
|
||||
label=_('Background job'),
|
||||
help_text=_("Process as a job to edit objects in the background"),
|
||||
required=False,
|
||||
)
|
||||
|
||||
return BulkDeleteForm
|
||||
|
||||
|
@ -9,10 +9,11 @@ from django.utils.translation import gettext as _
|
||||
from core.forms.mixins import SyncedDataMixin
|
||||
from netbox.choices import CSVDelimiterChoices, ImportFormatChoices, ImportMethodChoices
|
||||
from utilities.constants import CSV_DELIMITERS
|
||||
from utilities.forms.mixins import BackgroundJobMixin
|
||||
from utilities.forms.utils import parse_csv
|
||||
|
||||
|
||||
class BulkImportForm(SyncedDataMixin, forms.Form):
|
||||
class BulkImportForm(BackgroundJobMixin, SyncedDataMixin, forms.Form):
|
||||
import_method = forms.ChoiceField(
|
||||
choices=ImportMethodChoices,
|
||||
required=False
|
||||
@ -37,11 +38,6 @@ class BulkImportForm(SyncedDataMixin, forms.Form):
|
||||
help_text=_("The character which delimits CSV fields. Applies only to CSV format."),
|
||||
required=False
|
||||
)
|
||||
background_job = forms.BooleanField(
|
||||
label=_('Background job'),
|
||||
help_text=_("Enqueue a background job to complete the bulk import/update."),
|
||||
required=False,
|
||||
)
|
||||
|
||||
data_field = 'data'
|
||||
|
||||
|
@ -3,6 +3,8 @@ import re
|
||||
from django import forms
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from utilities.forms.mixins import BackgroundJobMixin
|
||||
|
||||
__all__ = (
|
||||
'BulkEditForm',
|
||||
'BulkRenameForm',
|
||||
@ -28,7 +30,7 @@ class ConfirmationForm(forms.Form):
|
||||
)
|
||||
|
||||
|
||||
class BulkEditForm(forms.Form):
|
||||
class BulkEditForm(BackgroundJobMixin, forms.Form):
|
||||
"""
|
||||
Provides bulk edit support for objects.
|
||||
|
||||
@ -37,12 +39,6 @@ class BulkEditForm(forms.Form):
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
|
@ -6,11 +6,20 @@ from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
__all__ = (
|
||||
'BackgroundJobMixin',
|
||||
'CheckLastUpdatedMixin',
|
||||
'DistanceValidationMixin',
|
||||
)
|
||||
|
||||
|
||||
class BackgroundJobMixin(forms.Form):
|
||||
background_job = forms.BooleanField(
|
||||
label=_('Background job'),
|
||||
help_text=_("Execute this task via a background job"),
|
||||
required=False,
|
||||
)
|
||||
|
||||
|
||||
class CheckLastUpdatedMixin(forms.Form):
|
||||
"""
|
||||
Checks whether the object being saved has been updated since the form was initialized. If so, validation fails.
|
||||
|
Loading…
Reference in New Issue
Block a user