Commit 72c693ce authored by Chirac's avatar Chirac
Browse files

Merge branch 'klafyvel' into 'master'

Fix #21

Closes #21

See merge request rezo/re2o!26
parents 54711698 fddeaa2e
......@@ -33,6 +33,7 @@ NewSwitchForm)
from __future__ import unicode_literals
from machines.models import Interface
from django import forms
from django.forms import ModelForm
from .models import Port, Switch, Room, Stack, ModelSwitch, ConstructorSwitch
......@@ -139,6 +140,12 @@ class EditRoomForm(ModelForm):
super(EditRoomForm, self).__init__(*args, prefix=prefix, **kwargs)
class CreatePortsForm(Form):
"""Permet de créer une liste de ports pour un switch."""
begin = forms.IntegerField(label="Début :", min_value=0)
end = forms.IntegerField(label="Fin :", min_value=0)
class EditModelSwitchForm(ModelForm):
"""Permet d'éediter un modèle de switch : nom et constructeur"""
class Meta:
......@@ -59,6 +59,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% if is_infra %}
{% include 'buttons/edit.html' with href='topologie:edit-switch' %}
{% include 'buttons/suppr.html' with href='machines:del-interface' %}
{% include 'buttons/add.html' with href='topologie:create-ports' desc='Création de ports'%}
{% endif %}
......@@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% if is_infra %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:edit-switch' id_switch %}"><i class="glyphicon glyphicon-edit"></i> Editer</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:new-port' id_switch %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un port</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:create-ports' id_switch %}"><i class="glyphicon glyphicon-plus"></i> Ajouter des ports</a>
{% endif %}
{% include "topologie/aff_port.html" with port_list=port_list %}
<br />
......@@ -35,6 +35,9 @@ from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^new_switch/$', views.new_switch, name='new-switch'),
url(r'^index_room/$', views.index_room, name='index-room'),
url(r'^new_room/$', views.new_room, name='new-room'),
url(r'^edit_room/(?P<room_id>[0-9]+)$', views.edit_room, name='edit-room'),
......@@ -35,6 +35,8 @@ coté models et forms de topologie
from __future__ import unicode_literals
import itertools
from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
......@@ -59,7 +61,8 @@ from topologie.forms import (
from users.views import form
from re2o.utils import SortTable
......@@ -181,7 +184,9 @@ def index_port(request, switch_id):
port_list = SortTable.sort(
......@@ -334,7 +339,7 @@ def del_port(request, port_id):
messages.success(request, "Le port a eté détruit")
messages.success(request, "Le port a été détruit")
except ProtectedError:
messages.error(request, "Le port %s est affecté à un autre objet,\
impossible de le supprimer" % port)
......@@ -467,7 +472,7 @@ def new_switch(request):
messages.success(request, "Le switch a été créé")
return redirect("/topologie/")
i_mbf_param = generate_ipv4_mbf_param( interface, False )
i_mbf_param = generate_ipv4_mbf_param(interface, False)
return form({
'topoform': switch,
'machineform': machine,
......@@ -477,6 +482,56 @@ def new_switch(request):
}, 'topologie/switch.html', request)
def create_ports(request, switch_id):
""" Création d'une liste de ports pour un switch."""
switch = Switch.objects.get(pk=switch_id)
except Switch.DoesNotExist:
messages.error(request, u"Switch inexistant")
return redirect("/topologie/")
s_begin = s_end = 0
nb_ports = switch.ports.count()
if nb_ports > 0:
ports = switch.ports.order_by('port').values('port')
s_begin = ports.first().get('port')
s_end = ports.last().get('port')
port_form = CreatePortsForm(
request.POST or None,
initial={'begin': s_begin, 'end': s_end}
if port_form.is_valid():
begin = port_form.cleaned_data['begin']
end = port_form.cleaned_data['end']
if end < begin:
messages.error(request, "Port de fin inférieur au port de début !")
return redirect("/topologie/switch/" + str(
if end - begin > switch.number:
messages.error(request, "Ce switch ne peut avoir autant de ports.")
return redirect("/topologie/switch/" + str(
begin_range = range(begin, s_begin)
end_range = range(s_end+1, end+1)
for i in itertools.chain(begin_range, end_range):
port = Port()
port.switch = switch
port.port = i
with transaction.atomic(), reversion.create_revision():
messages.success(request, "Création du port %d" % i)
except IntegrityError:
messages.error(request, "Création d'un port existant.")
return redirect("/topologie/switch/" + str(
return form({'topoform': port_form}, 'topologie/switch.html', request)
def edit_switch(request, switch_id):
......@@ -534,7 +589,7 @@ def edit_switch(request, switch_id):
messages.success(request, "Le switch a bien été modifié")
return redirect("/topologie/")
i_mbf_param = generate_ipv4_mbf_param( interface_form, False )
i_mbf_param = generate_ipv4_mbf_param(interface_form, False)
return form({
'topoform': switch_form,
'machineform': machine_form,
Supports Markdown
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