From d0a0a70e6e4395231452ca0bb8a3bd207269d71f Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Sat, 30 Sep 2017 10:04:18 +0200 Subject: [PATCH] =?UTF-8?q?Affichage=20de=20la=20page=20d'=C3=A9dition=20d?= =?UTF-8?q?'une=20liste=20de=20ports.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/forms.py | 9 ++++++++- machines/models.py | 5 +++++ machines/templates/machines/index_portlist.html | 6 +++--- machines/urls.py | 1 + machines/views.py | 12 +++++++++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/machines/forms.py b/machines/forms.py index cd4ac87d..afe781f1 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -24,7 +24,7 @@ from __future__ import unicode_literals from django.forms import ModelForm, Form, ValidationError from django import forms -from .models import Domain, Machine, Interface, IpList, MachineType, Extension, Mx, Text, Ns, Service, Vlan, Nas, IpType +from .models import Domain, Machine, Interface, IpList, MachineType, Extension, Mx, Text, Ns, Service, Vlan, Nas, IpType, PortList from django.db.models import Q from django.core.validators import validate_email @@ -229,5 +229,12 @@ class VlanForm(ModelForm): class DelVlanForm(Form): vlan = forms.ModelMultipleChoiceField(queryset=Vlan.objects.all(), label="Vlan actuels", widget=forms.CheckboxSelectMultiple) +class EditPortListForm(ModelForm): + tcp_ports = forms.CharField(required=False, label="Ports TCP") + udp_ports = forms.CharField(required=False, label="Ports UDP") + # interfaces = forms.ModelMultipleChoiceField(queryset=Interface.objects.filter(Q(has_public_ip=True)), label="Interface", widget=forms.CheckboxSelectMultiple) + class Meta: + model = PortList + fields = ['name'] diff --git a/machines/models.py b/machines/models.py index ff5dd1e9..91e16ab9 100644 --- a/machines/models.py +++ b/machines/models.py @@ -223,6 +223,7 @@ class Interface(models.Model): machine = models.ForeignKey('Machine', on_delete=models.CASCADE) type = models.ForeignKey('MachineType', on_delete=models.PROTECT) details = models.CharField(max_length=255, blank=True) + has_public_ip = False @cached_property def is_active(self): @@ -278,6 +279,7 @@ class Interface(models.Model): domain = None return str(domain) + class Domain(models.Model): PRETTY_NAME = "Domaine dns" @@ -447,6 +449,9 @@ class Port(models.Model): return str(self.begin) return '-'.join([str(self.begin), str(self.end)]) + def show_port(self): + return str(self) + @receiver(post_save, sender=Machine) def machine_post_save(sender, **kwargs): diff --git a/machines/templates/machines/index_portlist.html b/machines/templates/machines/index_portlist.html index 1ba3a61f..ce48e249 100644 --- a/machines/templates/machines/index_portlist.html +++ b/machines/templates/machines/index_portlist.html @@ -19,13 +19,13 @@ {% for pl in port_list %} {{pl.name}} - {{pl.tcp_ports}} - {{pl.udp_ports}} + {% for p in pl.tcp_ports%}{{p.show_port}}, {%endfor%} + {% for p in pl.udp_ports%}{{p.show_port}}, {%endfor%} {%comment%} {% include 'buttons/suppr.html' href='machines:del-portlist' id=pl.id %} - {% include 'buttons/edit.html' href='machines:edit-portlist' id=pl.id %} {%endcomment%} + {% include 'buttons/edit.html' with href='machines:edit-portlist' id=pl.id %} {%endfor%} diff --git a/machines/urls.py b/machines/urls.py index 4962609e..29f7668f 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -93,4 +93,5 @@ urlpatterns = [ url(r'^rest/zones/$', views.zones, name='zones'), 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'), ] diff --git a/machines/views.py b/machines/views.py index 4cb1149f..32b04c2e 100644 --- a/machines/views.py +++ b/machines/views.py @@ -48,6 +48,7 @@ from reversion.models import Version import re from .forms import NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm, MachineTypeForm, DelMachineTypeForm, ExtensionForm, DelExtensionForm, BaseEditInterfaceForm, BaseEditMachineForm from .forms import EditIpTypeForm, IpTypeForm, DelIpTypeForm, DomainForm, AliasForm, DelAliasForm, NsForm, DelNsForm, TextForm, DelTextForm, MxForm, DelMxForm, VlanForm, DelVlanForm, ServiceForm, DelServiceForm, NasForm, DelNasForm +from .forms import EditPortListForm from .models import IpType, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, Domain, Service, Service_link, Vlan, Nas, Text, PortList from users.models import User from users.models import all_has_access @@ -913,11 +914,20 @@ def history(request, object, id): @login_required -@permission_required('bureau') +@permission_required('cableur') def index_portlist(request): port_list = PortList.objects.all().order_by('name') return render(request, "machines/index_portlist.html", {'port_list':port_list}) +@login_required +@permission_required('bureau') +def edit_portlist(request, pk): + port_list_instance = get_object_or_404(PortList, pk=pk) + port_list = EditPortListForm(request.POST or None, instance=port_list_instance) + if port_list.is_valid(): + return redirect("/machines/index_portlist/") + return form({'machineform' : port_list}, 'machines/machine.html', request) + """ Framework Rest """ class JSONResponse(HttpResponse):