From 06ed7ac8a5b827c137f25627377200d738eeffe5 Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Fri, 13 Oct 2023 12:57:58 -0500 Subject: [PATCH] Fixes: #14023 - Fixes bulk disconnecting with multiple components attached to the same cable (#14029) * Fixes: #14023 - Fixes bulk disconnecting with multiple components attached to the same cable * Update netbox/dcim/views.py Co-authored-by: Jeremy Stretch * Update netbox/dcim/views.py Co-authored-by: Jeremy Stretch * Update netbox/dcim/views.py Co-authored-by: Daniel Sheppard * Code cleanup & i18n fix * Restore original termination count logic --------- Co-authored-by: Jeremy Stretch --- netbox/dcim/views.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 2f661e613..7c75dd26e 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -122,16 +122,18 @@ class BulkDisconnectView(GetReturnURLMixin, ObjectPermissionRequiredMixin, View) if form.is_valid(): with transaction.atomic(): - count = 0 + cable_ids = set() for obj in self.queryset.filter(pk__in=form.cleaned_data['pk']): - if obj.cable is None: - continue - obj.cable.delete() - count += 1 + if obj.cable: + cable_ids.add(obj.cable.pk) + count += 1 + for cable in Cable.objects.filter(pk__in=cable_ids): + cable.delete() - messages.success(request, "Disconnected {} {}".format( - count, self.queryset.model._meta.verbose_name_plural + messages.success(request, _("Disconnected {count} {type}").format( + count=count, + type=self.queryset.model._meta.verbose_name_plural )) return redirect(return_url)