diff --git a/machines/templates/machines/index_portlist.html b/machines/templates/machines/index_portlist.html index 81847af1..b7a9d00d 100644 --- a/machines/templates/machines/index_portlist.html +++ b/machines/templates/machines/index_portlist.html @@ -26,9 +26,7 @@ {% for p in pl.udp_ports_in %}{{p.show_port}}, {%endfor%} {% for p in pl.udp_ports_out %}{{p.show_port}}, {%endfor%} - {%comment%} - {% include 'buttons/suppr.html' href='machines:del-portlist' id=pl.id %} - {%endcomment%} + {% include 'buttons/suppr.html' with href='machines:del-portlist' id=pl.id %} {% include 'buttons/edit.html' with href='machines:edit-portlist' id=pl.id %} diff --git a/machines/urls.py b/machines/urls.py index 29f7668f..bae9535f 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -94,4 +94,5 @@ urlpatterns = [ url(r'^rest/service_servers/$', views.service_servers, name='service-servers'), url(r'index_portlist/$', views.index_portlist, name='index-portlist'), url(r'^edit_portlist/(?P[0-9]+)$', views.edit_portlist, name='edit-portlist'), + url(r'^del_portlist/(?P[0-9]+)$', views.del_portlist, name='del-portlist'), ] diff --git a/machines/views.py b/machines/views.py index 31e9545f..e394fdc1 100644 --- a/machines/views.py +++ b/machines/views.py @@ -922,7 +922,11 @@ def index_portlist(request): @login_required @permission_required('bureau') def edit_portlist(request, pk): - port_list_instance = get_object_or_404(PortList, pk=pk) + try: + port_list_instance = PortList.objects.get(pk=pk) + except PortList.DoesNotExist: + messages.error(request, "Liste de ports inexistante") + return redirect("/machines/index_portlist/") port_list = EditPortListForm(request.POST or None, instance=port_list_instance) if port_list.is_valid(): with transaction.atomic(), reversion.create_revision(): @@ -931,6 +935,23 @@ def edit_portlist(request, pk): return redirect("/machines/index_portlist/") return form({'machineform' : port_list}, 'machines/machine.html', request) +@login_required +@permission_required('bureau') +def del_portlist(request, pk): + try: + port_list_instance = PortList.objects.get(pk=pk) + except PortList.DoesNotExist: + messages.error(request, "Liste de ports inexistante") + return redirect("/machines/index_portlist/") + if port_list_instance.interfaces.all(): + messages.error(request, "Cette liste de ports est utilisée") + return redirect("/machines/index_portlist/") + port_list_instance.delete() + messages.success(request, "La liste de ports a été supprimée") + return redirect("/machines/index_portlist/") + + + """ Framework Rest """ class JSONResponse(HttpResponse):