Closes #19891: Bulk operation jobs (#19897)

* Add background_job toggle to BulkEditForm

* Account for bug fix in v4.3.4

* Enable background jobs for bulk edit & bulk delete

* Move background_job field to a mixin

* Cosmetic improvements

* Misc cleanup

* Fix BackgroundJobMixin
This commit is contained in:
Jeremy Stretch
2025-07-18 09:24:38 -04:00
committed by GitHub
parent 7f2b744a53
commit cebc56e5cc
11 changed files with 121 additions and 31 deletions
+15 -1
View File
@@ -1,6 +1,10 @@
from dataclasses import dataclass
from typing import List
from django.contrib import messages
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from netbox.jobs import AsyncViewJob
from utilities.request import copy_safe_request
@@ -38,9 +42,19 @@ def process_request_as_job(view, request, name=None):
request_copy._background = True
# Enqueue a job to perform the work in the background
return AsyncViewJob.enqueue(
job = AsyncViewJob.enqueue(
name=name,
user=request.user,
view_cls=view,
request=request_copy,
)
# Record a message on the original request indicating deferral to a background job
msg = _('Created background job {id}: <a href="{url}">{name}</a>').format(
id=job.pk,
url=job.get_absolute_url(),
name=job.name
)
messages.info(request, mark_safe(msg))
return job