Commit b57fed74 authored by LEVY-FALK Hugo's avatar LEVY-FALK Hugo Committed by root

Affectation de configuration de ports à une interface.

parent ad67b9cb
......@@ -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:
......
# -*- 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'),
),
]
......@@ -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"
......
......@@ -91,6 +91,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<i class="glyphicon glyphicon-edit"></i> Gerer les alias
</a>
</li>
<li>
<a href="{% url 'machines:port-config' interface.id%}">
<i class="glyphicon glyphicon-edit"></i> Gerer la configuration des ports
</a>
</li>
<li>
<a href="{% url 'machines:history' 'interface' interface.id %}">
<i class="glyphicon glyphicon-time"></i> Historique
......
......@@ -96,4 +96,6 @@ urlpatterns = [
url(r'^edit_portlist/(?P<pk>[0-9]+)$', views.edit_portlist, name='edit-portlist'),
url(r'^del_portlist/(?P<pk>[0-9]+)$', views.del_portlist, name='del-portlist'),
url(r'^add_portlist/$', views.add_portlist, name='add-portlist'),
url(r'^port_config/(?P<pk>[0-9]+)$', views.configure_ports, name='port-config'),
]
......@@ -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 """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment