mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08: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
|
import re
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from django import forms
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRel
|
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRel
|
||||||
from django.contrib.contenttypes.models import ContentType
|
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.export import TableExport
|
||||||
from utilities.forms import BulkRenameForm, ConfirmationForm, restrict_form_fields
|
from utilities.forms import BulkRenameForm, ConfirmationForm, restrict_form_fields
|
||||||
from utilities.forms.bulk_import import BulkImportForm
|
from utilities.forms.bulk_import import BulkImportForm
|
||||||
|
from utilities.forms.mixins import BackgroundJobMixin
|
||||||
from utilities.htmx import htmx_partial
|
from utilities.htmx import htmx_partial
|
||||||
from utilities.jobs import AsyncJobData, is_background_request, process_request_as_job
|
from utilities.jobs import AsyncJobData, is_background_request, process_request_as_job
|
||||||
from utilities.permissions import get_permission_for_model
|
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
|
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)
|
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
|
return BulkDeleteForm
|
||||||
|
|
||||||
|
@ -9,10 +9,11 @@ from django.utils.translation import gettext as _
|
|||||||
from core.forms.mixins import SyncedDataMixin
|
from core.forms.mixins import SyncedDataMixin
|
||||||
from netbox.choices import CSVDelimiterChoices, ImportFormatChoices, ImportMethodChoices
|
from netbox.choices import CSVDelimiterChoices, ImportFormatChoices, ImportMethodChoices
|
||||||
from utilities.constants import CSV_DELIMITERS
|
from utilities.constants import CSV_DELIMITERS
|
||||||
|
from utilities.forms.mixins import BackgroundJobMixin
|
||||||
from utilities.forms.utils import parse_csv
|
from utilities.forms.utils import parse_csv
|
||||||
|
|
||||||
|
|
||||||
class BulkImportForm(SyncedDataMixin, forms.Form):
|
class BulkImportForm(BackgroundJobMixin, SyncedDataMixin, forms.Form):
|
||||||
import_method = forms.ChoiceField(
|
import_method = forms.ChoiceField(
|
||||||
choices=ImportMethodChoices,
|
choices=ImportMethodChoices,
|
||||||
required=False
|
required=False
|
||||||
@ -37,11 +38,6 @@ class BulkImportForm(SyncedDataMixin, forms.Form):
|
|||||||
help_text=_("The character which delimits CSV fields. Applies only to CSV format."),
|
help_text=_("The character which delimits CSV fields. Applies only to CSV format."),
|
||||||
required=False
|
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'
|
data_field = 'data'
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ import re
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
from utilities.forms.mixins import BackgroundJobMixin
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'BulkEditForm',
|
'BulkEditForm',
|
||||||
'BulkRenameForm',
|
'BulkRenameForm',
|
||||||
@ -28,7 +30,7 @@ class ConfirmationForm(forms.Form):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BulkEditForm(forms.Form):
|
class BulkEditForm(BackgroundJobMixin, forms.Form):
|
||||||
"""
|
"""
|
||||||
Provides bulk edit support for objects.
|
Provides bulk edit support for objects.
|
||||||
|
|
||||||
@ -37,12 +39,6 @@ class BulkEditForm(forms.Form):
|
|||||||
"""
|
"""
|
||||||
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):
|
||||||
"""
|
"""
|
||||||
|
@ -6,11 +6,20 @@ from django.core.validators import MaxValueValidator, MinValueValidator
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
|
'BackgroundJobMixin',
|
||||||
'CheckLastUpdatedMixin',
|
'CheckLastUpdatedMixin',
|
||||||
'DistanceValidationMixin',
|
'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):
|
class CheckLastUpdatedMixin(forms.Form):
|
||||||
"""
|
"""
|
||||||
Checks whether the object being saved has been updated since the form was initialized. If so, validation fails.
|
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