Skip to content

Commit

Permalink
chore(nit): Avoid negations in if-conditions. Return early.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jan 23, 2025
1 parent 996cc35 commit c2559fe
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions data_registry/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,33 +207,30 @@ def get_form(self, request, obj=None, **kwargs):
form.base_fields["active_job"].widget.can_add_related = False
return form

@admin.action(description="Create a job for the selected publication")
@admin.action(description="Create a job for each selected publication")
def create_job(self, request, queryset):
created = 0
not_created = 0
created = 0
for collection in queryset:
if not collection.is_out_of_date() and not collection.job_set.incomplete():
if collection.is_out_of_date() or collection.job_set.incomplete():
not_created += 1
else:
collection.job_set.create()
created += 1
else:
not_created += 1

if not_created:
self.message_user(
request,
f"Created {created} jobs. "
f"{not_created} publications either have incomplete jobs or will be scheduled shortly",
f"{not_created} publications either have incomplete jobs or will be scheduled shortly.",
messages.WARNING,
)
else:
self.message_user(
request,
f"Created {created} jobs.",
messages.INFO,
)
content_type = ContentType.objects.get_for_model(Job)
return HttpResponseRedirect(reverse(f"admin:{content_type.app_label}_{content_type.model}_changelist"))
# Stay on the same page, in case the user wants to retry.
return None

return None
self.message_user(request, f"Created {created} jobs.", messages.SUCCESS)
content_type = ContentType.objects.get_for_model(Job)
return HttpResponseRedirect(reverse(f"admin:{content_type.app_label}_{content_type.model}_changelist"))


class UnsuccessfulFilter(admin.SimpleListFilter):
Expand Down

0 comments on commit c2559fe

Please sign in to comment.