From 779c2be2de928f1353761087c411331b76e72af5 Mon Sep 17 00:00:00 2001 From: LEVY-FALK Hugo Date: Sun, 1 Oct 2017 17:19:42 +0200 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20de=20liste=20de=20ports.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/forms.py | 2 ++ machines/templates/machines/index_portlist.html | 2 +- machines/urls.py | 1 + machines/views.py | 12 ++++++++++-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/machines/forms.py b/machines/forms.py index dec2cad2..ee84adfc 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -262,6 +262,8 @@ class EditPortListForm(ModelForm): split = r',\s+' ip_range = r'\d+-\d+' + if instance.pk == None: # On ne peut pas créer de ForeignKey sur des objets sans pk + instance.save() def add_port(string, protocole, mode): for p in re.split(split, string): if not p: diff --git a/machines/templates/machines/index_portlist.html b/machines/templates/machines/index_portlist.html index b7a9d00d..c21ea30e 100644 --- a/machines/templates/machines/index_portlist.html +++ b/machines/templates/machines/index_portlist.html @@ -6,7 +6,7 @@ {% block content %}

Liste des configurations de ports

- Ajouter une configuration + Ajouter une configuration diff --git a/machines/urls.py b/machines/urls.py index bae9535f..51cf962e 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -95,4 +95,5 @@ urlpatterns = [ 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'), + url(r'^add_portlist/$', views.add_portlist, name='add-portlist'), ] diff --git a/machines/views.py b/machines/views.py index e394fdc1..9c1ad718 100644 --- a/machines/views.py +++ b/machines/views.py @@ -929,8 +929,7 @@ def edit_portlist(request, pk): 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(): - port_list.save() + port_list.save() messages.success(request, "Liste de ports modifiée") return redirect("/machines/index_portlist/") return form({'machineform' : port_list}, 'machines/machine.html', request) @@ -950,6 +949,15 @@ def del_portlist(request, pk): messages.success(request, "La liste de ports a été supprimée") return redirect("/machines/index_portlist/") +@login_required +@permission_required('bureau') +def add_portlist(request): + port_list = EditPortListForm(request.POST or None) + if port_list.is_valid(): + port_list.save() + messages.success(request, "Liste de ports créée") + return redirect("/machines/index_portlist/") + return form({'machineform' : port_list}, 'machines/machine.html', request) """ Framework Rest """