Use an informative name for the job

This commit is contained in:
Jeremy Stretch 2025-07-03 10:31:27 -04:00
parent 99b23d0df1
commit 3f7d24b596
3 changed files with 9 additions and 4 deletions

View File

@ -116,7 +116,7 @@ class Job(models.Model):
verbose_name_plural = _('jobs')
def __str__(self):
return str(self.job_id)
return self.name
def get_absolute_url(self):
# TODO: Employ dynamic registration

View File

@ -506,8 +506,12 @@ class BulkImportView(GetReturnURLMixin, BaseMultiObjectView):
# If indicated, defer this request to a background job & redirect the user
if form.cleaned_data['background_job']:
if job := process_request_as_job(self.__class__, request):
msg = _('Created background job <a href="{url}">{job}</a>').format(
job_name = _('Bulk import {count} {object_type}').format(
count=len(form.cleaned_data['data']),
object_type=model._meta.verbose_name_plural,
)
if job := process_request_as_job(self.__class__, request, name=job_name):
msg = _('Created background job {job.pk}: <a href="{url}">{job.name}</a>').format(
url=job.get_absolute_url(),
job=job
)

View File

@ -24,7 +24,7 @@ def is_background_request(request):
return getattr(request, '_background', False)
def process_request_as_job(view, request):
def process_request_as_job(view, request, name=None):
"""
Process a request using a view as a background job.
"""
@ -39,6 +39,7 @@ def process_request_as_job(view, request):
# Enqueue a job to perform the work in the background
return AsyncViewJob.enqueue(
name=name,
user=request.user,
view_cls=view,
request=request_copy,