From 56eb5d28d1f1bc56c7061440dd04bc2349ee2140 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 26 Jun 2025 20:42:17 -0400 Subject: [PATCH] Remove ClusterRemoveDevicesView (anti-pattern) --- netbox/templates/generic/bulk_remove.html | 72 ------------------- .../virtualization/cluster/devices.html | 13 ---- .../buttons/bulk_remove_devices.html | 6 -- netbox/virtualization/views.py | 48 +------------ 4 files changed, 2 insertions(+), 137 deletions(-) delete mode 100644 netbox/templates/generic/bulk_remove.html delete mode 100644 netbox/templates/virtualization/cluster/devices.html delete mode 100644 netbox/utilities/templates/buttons/bulk_remove_devices.html diff --git a/netbox/templates/generic/bulk_remove.html b/netbox/templates/generic/bulk_remove.html deleted file mode 100644 index d0ba23097..000000000 --- a/netbox/templates/generic/bulk_remove.html +++ /dev/null @@ -1,72 +0,0 @@ -{% extends 'generic/_base.html' %} -{% load helpers %} -{% load render_table from django_tables2 %} -{% load i18n %} - -{% comment %} -Blocks: - - title: Page title - - tabs: Page tabs - - content: Primary page content - -Context: - - form: The bulk edit form class - - parent_obj: The parent object - - table: A table of objects being removed - - obj_type_plural: The plural form of the object type - - return_url: The URL to which the user is redirected after submitting the form -{% endcomment %} - -{% block title %} - {% trans "Remove" %} {{ table.rows|length }} {{ obj_type_plural|bettertitle }}? -{% endblock %} - -{% block tabs %} - -{% endblock tabs %} - -{% block content %} -
- -
-
-
- {% render_table table 'inc/table.html' %} -
-
-
- {% csrf_token %} - {% for field in form.hidden_fields %} - {{ field }} - {% endfor %} -
- {% trans "Cancel" %} - -
-
-
-
-{% endblock content %} diff --git a/netbox/templates/virtualization/cluster/devices.html b/netbox/templates/virtualization/cluster/devices.html deleted file mode 100644 index a71fab8b5..000000000 --- a/netbox/templates/virtualization/cluster/devices.html +++ /dev/null @@ -1,13 +0,0 @@ -{% extends 'generic/object_children.html' %} -{% load i18n %} - -{% block bulk_delete_controls %} - {{ block.super }} - {% if 'bulk_remove_devices' in actions %} - - {% endif %} -{% endblock bulk_delete_controls %} diff --git a/netbox/utilities/templates/buttons/bulk_remove_devices.html b/netbox/utilities/templates/buttons/bulk_remove_devices.html deleted file mode 100644 index 3a5d45420..000000000 --- a/netbox/utilities/templates/buttons/bulk_remove_devices.html +++ /dev/null @@ -1,6 +0,0 @@ -{% load i18n %} -{% if url %} - -{% endif %} diff --git a/netbox/virtualization/views.py b/netbox/virtualization/views.py index 7a638498d..81a10b211 100644 --- a/netbox/virtualization/views.py +++ b/netbox/virtualization/views.py @@ -204,6 +204,7 @@ class ClusterVirtualMachinesView(generic.ObjectChildrenView): table = tables.VirtualMachineTable filterset = filtersets.VirtualMachineFilterSet filterset_form = forms.VirtualMachineFilterForm + actions = (Edit, Delete, BulkEdit) tab = ViewTab( label=_('Virtual Machines'), badge=lambda obj: obj.virtual_machines.count(), @@ -222,8 +223,7 @@ class ClusterDevicesView(generic.ObjectChildrenView): table = DeviceTable filterset = DeviceFilterSet filterset_form = DeviceFilterForm - template_name = 'virtualization/cluster/devices.html' - actions = (Add, BulkExport, BulkImport, BulkEdit) + actions = (Edit, Delete, BulkEdit) tab = ViewTab( label=_('Devices'), badge=lambda obj: obj.devices.count(), @@ -311,50 +311,6 @@ class ClusterAddDevicesView(generic.ObjectEditView): }) -@register_model_view(Cluster, 'remove_devices', path='devices/remove') -class ClusterRemoveDevicesView(generic.ObjectEditView): - queryset = Cluster.objects.all() - form = forms.ClusterRemoveDevicesForm - template_name = 'generic/bulk_remove.html' - - def post(self, request, pk): - - cluster = get_object_or_404(self.queryset, pk=pk) - - if '_confirm' in request.POST: - form = self.form(request.POST) - if form.is_valid(): - - device_pks = form.cleaned_data['pk'] - with transaction.atomic(using=router.db_for_write(Device)): - - # Remove the selected Devices from the Cluster - for device in Device.objects.filter(pk__in=device_pks): - device.cluster = None - device.save() - - messages.success(request, _("Removed {count} devices from cluster {cluster}").format( - count=len(device_pks), - cluster=cluster - )) - return redirect(cluster.get_absolute_url()) - - else: - form = self.form(initial={'pk': request.POST.getlist('pk')}) - - selected_objects = Device.objects.filter(pk__in=form.initial['pk']) - device_table = DeviceTable(list(selected_objects), orderable=False) - device_table.configure(request) - - return render(request, self.template_name, { - 'form': form, - 'parent_obj': cluster, - 'table': device_table, - 'obj_type_plural': 'devices', - 'return_url': cluster.get_absolute_url(), - }) - - # # Virtual machines #