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 <jstretch@netboxlabs.com>

* Update netbox/dcim/views.py

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>

* Update netbox/dcim/views.py

Co-authored-by: Daniel Sheppard <dans@dansheps.com>

* Code cleanup & i18n fix

* Restore original termination count logic

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
Daniel Sheppard 2023-10-13 12:57:58 -05:00 committed by GitHub
parent 72f01b3e89
commit 06ed7ac8a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,16 +122,18 @@ class BulkDisconnectView(GetReturnURLMixin, ObjectPermissionRequiredMixin, View)
if form.is_valid(): if form.is_valid():
with transaction.atomic(): with transaction.atomic():
count = 0 count = 0
cable_ids = set()
for obj in self.queryset.filter(pk__in=form.cleaned_data['pk']): for obj in self.queryset.filter(pk__in=form.cleaned_data['pk']):
if obj.cable is None: if obj.cable:
continue cable_ids.add(obj.cable.pk)
obj.cable.delete() count += 1
count += 1 for cable in Cable.objects.filter(pk__in=cable_ids):
cable.delete()
messages.success(request, "Disconnected {} {}".format( messages.success(request, _("Disconnected {count} {type}").format(
count, self.queryset.model._meta.verbose_name_plural count=count,
type=self.queryset.model._meta.verbose_name_plural
)) ))
return redirect(return_url) return redirect(return_url)