From f56ca250ba7ba51927fd28ba69919d587bac8159 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Mon, 2 Oct 2017 00:08:07 +0200 Subject: [PATCH] =?UTF-8?q?Affectation=20de=20configuration=20de=20ports?= =?UTF-8?q?=20=C3=A0=20une=20interface.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/forms.py | 10 ++++---- .../migrations/0061_auto_20171001_1727.py | 24 +++++++++++++++++++ machines/models.py | 3 +++ machines/templates/machines/aff_machines.html | 5 ++++ machines/urls.py | 2 ++ machines/views.py | 16 ++++++++++++- 6 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 machines/migrations/0061_auto_20171001_1727.py diff --git a/machines/forms.py b/machines/forms.py index 863a4d6f..34d9652f 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -52,14 +52,14 @@ class BaseEditMachineForm(EditMachineForm): class EditInterfaceForm(ModelForm): class Meta: model = Interface - fields = '__all__' + # fields = '__all__' + exclude = ['port_lists'] def __init__(self, *args, **kwargs): super(EditInterfaceForm, self).__init__(*args, **kwargs) self.fields['mac_address'].label = 'Adresse mac' self.fields['type'].label = 'Type de machine' self.fields['type'].empty_label = "Séléctionner un type de machine" - self.fields['port_lists'].label = "Configuration des ports" if "machine" in self.fields: self.fields['machine'].queryset = Machine.objects.all().select_related('user') @@ -232,10 +232,10 @@ class VlanForm(ModelForm): class DelVlanForm(Form): vlan = forms.ModelMultipleChoiceField(queryset=Vlan.objects.all(), label="Vlan actuels", widget=forms.CheckboxSelectMultiple) -class EditPortForm(ModelForm): +class EditPortConfigForm(ModelForm): class Meta: - model = Port - fields = '__all__' + model = Interface + fields = ['port_lists'] class EditPortListForm(ModelForm): class Meta: diff --git a/machines/migrations/0061_auto_20171001_1727.py b/machines/migrations/0061_auto_20171001_1727.py new file mode 100644 index 00000000..661f9fd3 --- /dev/null +++ b/machines/migrations/0061_auto_20171001_1727.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-10-01 15:27 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0060_port_io'), + ] + + operations = [ + migrations.RemoveField( + model_name='portlist', + name='interfaces', + ), + migrations.AddField( + model_name='interface', + name='port_lists', + field=models.ManyToManyField(to='machines.PortList'), + ), + ] diff --git a/machines/models.py b/machines/models.py index 7c13e8eb..bf5a774d 100644 --- a/machines/models.py +++ b/machines/models.py @@ -279,6 +279,9 @@ class Interface(models.Model): domain = None return str(domain) + def has_private_ip(self): + return IPAddress(str(self.ipv4)).is_private() + class Domain(models.Model): PRETTY_NAME = "Domaine dns" diff --git a/machines/templates/machines/aff_machines.html b/machines/templates/machines/aff_machines.html index a09d8868..c4a2dd56 100644 --- a/machines/templates/machines/aff_machines.html +++ b/machines/templates/machines/aff_machines.html @@ -91,6 +91,11 @@ with this program; if not, write to the Free Software Foundation, Inc., Gerer les alias +
  • + + Gerer la configuration des ports + +
  • Historique diff --git a/machines/urls.py b/machines/urls.py index 51cf962e..62576a4e 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -96,4 +96,6 @@ urlpatterns = [ 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'), + url(r'^port_config/(?P[0-9]+)$', views.configure_ports, name='port-config'), + ] diff --git a/machines/views.py b/machines/views.py index 54828999..9aaf90e7 100644 --- a/machines/views.py +++ b/machines/views.py @@ -48,7 +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, EditPortForm +from .forms import EditPortListForm, EditPortConfigForm from .models import IpType, Machine, Interface, IpList, MachineType, Extension, Mx, Ns, Domain, Service, Service_link, Vlan, Nas, Text, PortList, Port from users.models import User from users.models import all_has_access @@ -993,6 +993,20 @@ def add_portlist(request): return redirect("/machines/index_portlist/") return form({'machineform' : port_list}, 'machines/machine.html', request) +@login_required +@permission_required('cableur') +def configure_ports(request, pk): + try: + interface_instance = Interface.objects.get(pk=pk) + except Interface.DoesNotExist: + messages.error(request, u"Interface inexistante" ) + return redirect("/machines") + interface = EditPortConfigForm(request.POST or None, instance=interface_instance) + if interface.is_valid(): + interface.save() + messages.success(request, "Configuration des ports mise à jour.") + return redirect("/machines/") + return form({'interfaceform' : interface}, 'machines/machine.html', request) """ Framework Rest """