Skip to content

Commit

Permalink
Fixes: #14023 - Fixes bulk disconnecting with multiple components att…
Browse files Browse the repository at this point in the history
…ached 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>
  • Loading branch information
DanSheps and jeremystretch authored Oct 13, 2023
1 parent 72f01b3 commit 06ed7ac
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions netbox/dcim/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,18 @@ def post(self, request):
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

messages.success(request, "Disconnected {} {}".format(
count, self.queryset.model._meta.verbose_name_plural
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 {count} {type}").format(
count=count,
type=self.queryset.model._meta.verbose_name_plural
))

return redirect(return_url)
Expand Down

0 comments on commit 06ed7ac

Please sign in to comment.