mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Remove ClusterRemoveDevicesView (anti-pattern)
This commit is contained in:
parent
3e26ce950c
commit
56eb5d28d1
@ -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 %}
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link active" type="button" role="tab" aria-controls="edit-form" aria-selected="true">
|
||||
{% trans "Bulk Remove" %}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
{% endblock tabs %}
|
||||
|
||||
{% block content %}
|
||||
<div class="tab-pane show active" role="tabpanel">
|
||||
<div class="alert alert-danger bg-danger-subtle" role="alert">
|
||||
<div class="d-flex">
|
||||
<div>
|
||||
<i class="mdi mdi-alert-octagon p-2"></i>
|
||||
</div>
|
||||
<div>
|
||||
<h4 class="alert-title">{% trans "Confirm Bulk Removal" %}</h4>
|
||||
{% blocktrans trimmed with count=table.rows|length %}
|
||||
The following operation will remove {{ count }} {{ obj_type_plural }} from {{ parent_obj }}. Please
|
||||
carefully review the {{ obj_type_plural }} to be removed and confirm below.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container-fluid px-0">
|
||||
<div class="card">
|
||||
<div class="table-responsive">
|
||||
{% render_table table 'inc/table.html' %}
|
||||
</div>
|
||||
</div>
|
||||
<form action="." method="post" class="form">
|
||||
{% csrf_token %}
|
||||
{% for field in form.hidden_fields %}
|
||||
{{ field }}
|
||||
{% endfor %}
|
||||
<div class="text-end">
|
||||
<a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
|
||||
<button type="submit" name="_confirm" class="btn btn-danger">
|
||||
{% blocktrans trimmed with count=table.rows|length %}
|
||||
Remove these {{ count }} {{ obj_type_plural }}
|
||||
{% endblocktrans %}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
@ -1,13 +0,0 @@
|
||||
{% extends 'generic/object_children.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block bulk_delete_controls %}
|
||||
{{ block.super }}
|
||||
{% if 'bulk_remove_devices' in actions %}
|
||||
<button type="submit" name="_remove"
|
||||
{% formaction %}="{% url 'virtualization:cluster_remove_devices' pk=object.pk %}?return_url={{ return_url }}"
|
||||
class="btn btn-danger">
|
||||
<span class="mdi mdi-trash-can-outline" aria-hidden="true"></span> {% trans "Remove Selected" %}
|
||||
</button>
|
||||
{% endif %}
|
||||
{% endblock bulk_delete_controls %}
|
@ -1,6 +0,0 @@
|
||||
{% load i18n %}
|
||||
{% if url %}
|
||||
<button type="submit" name="_remove" {% formaction %}="{{ url }}?return_url={{ return_url }}" class="btn btn-red">
|
||||
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> {{ label }}
|
||||
</button>
|
||||
{% endif %}
|
@ -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
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user