mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-26 00:43:46 +00:00
Pep8 et pylint compliance
This commit is contained in:
parent
457a098406
commit
3965489e95
4 changed files with 27 additions and 20 deletions
|
@ -143,6 +143,3 @@ class CreatePortsForm(Form):
|
||||||
"""Permet de créer une liste de ports pour un switch."""
|
"""Permet de créer une liste de ports pour un switch."""
|
||||||
begin = forms.IntegerField(label="Début :", min_value=0)
|
begin = forms.IntegerField(label="Début :", min_value=0)
|
||||||
end = forms.IntegerField(label="Fin :", min_value=0)
|
end = forms.IntegerField(label="Fin :", min_value=0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@ class Switch(models.Model):
|
||||||
raise ValidationError({'stack_member_id': "L'id dans la stack\
|
raise ValidationError({'stack_member_id': "L'id dans la stack\
|
||||||
ne peut être nul"})
|
ne peut être nul"})
|
||||||
|
|
||||||
|
|
||||||
class Port(models.Model):
|
class Port(models.Model):
|
||||||
""" Definition d'un port. Relié à un switch(foreign_key),
|
""" Definition d'un port. Relié à un switch(foreign_key),
|
||||||
un port peut etre relié de manière exclusive à :
|
un port peut etre relié de manière exclusive à :
|
||||||
|
|
|
@ -35,7 +35,9 @@ from . import views
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.index, name='index'),
|
url(r'^$', views.index, name='index'),
|
||||||
url(r'^new_switch/$', views.new_switch, name='new-switch'),
|
url(r'^new_switch/$', views.new_switch, name='new-switch'),
|
||||||
url(r'^create_ports/(?P<switch_id>[0-9]+)$', views.create_ports, name='create-ports'),
|
url(r'^create_ports/(?P<switch_id>[0-9]+)$',
|
||||||
|
views.create_ports,
|
||||||
|
name='create-ports'),
|
||||||
url(r'^index_room/$', views.index_room, name='index-room'),
|
url(r'^index_room/$', views.index_room, name='index-room'),
|
||||||
url(r'^new_room/$', views.new_room, name='new-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'),
|
url(r'^edit_room/(?P<room_id>[0-9]+)$', views.edit_room, name='edit-room'),
|
||||||
|
|
|
@ -53,7 +53,13 @@ from topologie.forms import AddPortForm, EditRoomForm, StackForm
|
||||||
from topologie.forms import CreatePortsForm
|
from topologie.forms import CreatePortsForm
|
||||||
from users.views import form
|
from users.views import form
|
||||||
from re2o.utils import SortTable
|
from re2o.utils import SortTable
|
||||||
from machines.forms import DomainForm, NewMachineForm, EditMachineForm, EditInterfaceForm, AddInterfaceForm
|
from machines.forms import (
|
||||||
|
DomainForm,
|
||||||
|
NewMachineForm,
|
||||||
|
EditMachineForm,
|
||||||
|
EditInterfaceForm,
|
||||||
|
AddInterfaceForm
|
||||||
|
)
|
||||||
from machines.views import generate_ipv4_mbf_param
|
from machines.views import generate_ipv4_mbf_param
|
||||||
from preferences.models import AssoOption, GeneralOption
|
from preferences.models import AssoOption, GeneralOption
|
||||||
|
|
||||||
|
@ -141,7 +147,9 @@ def index_port(request, switch_id):
|
||||||
.select_related('room')\
|
.select_related('room')\
|
||||||
.select_related('machine_interface__domain__extension')\
|
.select_related('machine_interface__domain__extension')\
|
||||||
.select_related('machine_interface__machine__user')\
|
.select_related('machine_interface__machine__user')\
|
||||||
.select_related('related__switch__switch_interface__domain__extension')\
|
.select_related(
|
||||||
|
'related__switch__switch_interface__domain__extension'
|
||||||
|
)\
|
||||||
.select_related('switch')
|
.select_related('switch')
|
||||||
port_list = SortTable.sort(
|
port_list = SortTable.sort(
|
||||||
port_list,
|
port_list,
|
||||||
|
@ -403,7 +411,7 @@ def new_switch(request):
|
||||||
reversion.set_comment("Création")
|
reversion.set_comment("Création")
|
||||||
messages.success(request, "Le switch a été créé")
|
messages.success(request, "Le switch a été créé")
|
||||||
return redirect("/topologie/")
|
return redirect("/topologie/")
|
||||||
i_mbf_param = generate_ipv4_mbf_param( interface, False )
|
i_mbf_param = generate_ipv4_mbf_param(interface, False)
|
||||||
return form({
|
return form({
|
||||||
'topoform': switch,
|
'topoform': switch,
|
||||||
'machineform': machine,
|
'machineform': machine,
|
||||||
|
@ -412,6 +420,7 @@ def new_switch(request):
|
||||||
'i_mbf_param': i_mbf_param
|
'i_mbf_param': i_mbf_param
|
||||||
}, 'topologie/switch.html', request)
|
}, 'topologie/switch.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required('infra')
|
@permission_required('infra')
|
||||||
def create_ports(request, switch_id):
|
def create_ports(request, switch_id):
|
||||||
|
@ -431,13 +440,11 @@ def create_ports(request, switch_id):
|
||||||
|
|
||||||
port_form = CreatePortsForm(
|
port_form = CreatePortsForm(
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
initial={'begin':s_begin,'end':s_end}
|
initial={'begin': s_begin, 'end': s_end}
|
||||||
)
|
)
|
||||||
if port_form.is_valid():
|
if port_form.is_valid():
|
||||||
begin = port_form.cleaned_data['begin']
|
begin = port_form.cleaned_data['begin']
|
||||||
end = port_form.cleaned_data['end']
|
end = port_form.cleaned_data['end']
|
||||||
b = []
|
|
||||||
e = []
|
|
||||||
if end < begin:
|
if end < begin:
|
||||||
messages.error(request, "Port de fin inférieur au port de début !")
|
messages.error(request, "Port de fin inférieur au port de début !")
|
||||||
return redirect("/topologie/switch/" + str(switch.id))
|
return redirect("/topologie/switch/" + str(switch.id))
|
||||||
|
@ -445,15 +452,15 @@ def create_ports(request, switch_id):
|
||||||
messages.error(request, "Ce switch ne peut avoir autant de ports.")
|
messages.error(request, "Ce switch ne peut avoir autant de ports.")
|
||||||
return redirect("/topologie/switch/" + str(switch.id))
|
return redirect("/topologie/switch/" + str(switch.id))
|
||||||
|
|
||||||
b = range(begin, s_begin)
|
begin_range = range(begin, s_begin)
|
||||||
e = range(s_end+1, end+1)
|
end_range = range(s_end+1, end+1)
|
||||||
for i in itertools.chain(b,e):
|
for i in itertools.chain(begin_range, end_range):
|
||||||
p = Port()
|
port = Port()
|
||||||
p.switch = switch
|
port.switch = switch
|
||||||
p.port = i
|
port.port = i
|
||||||
try:
|
try:
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
p.save()
|
port.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Création")
|
reversion.set_comment("Création")
|
||||||
messages.success(request, "Création du port %d" % i)
|
messages.success(request, "Création du port %d" % i)
|
||||||
|
@ -461,7 +468,7 @@ def create_ports(request, switch_id):
|
||||||
messages.error(request, "Création d'un port existant.")
|
messages.error(request, "Création d'un port existant.")
|
||||||
return redirect("/topologie/switch/" + str(switch.id))
|
return redirect("/topologie/switch/" + str(switch.id))
|
||||||
|
|
||||||
return form({'topoform': port_form,}, 'topologie/switch.html', request)
|
return form({'topoform': port_form}, 'topologie/switch.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -521,7 +528,7 @@ def edit_switch(request, switch_id):
|
||||||
)
|
)
|
||||||
messages.success(request, "Le switch a bien été modifié")
|
messages.success(request, "Le switch a bien été modifié")
|
||||||
return redirect("/topologie/")
|
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({
|
return form({
|
||||||
'topoform': switch_form,
|
'topoform': switch_form,
|
||||||
'machineform': machine_form,
|
'machineform': machine_form,
|
||||||
|
|
Loading…
Reference in a new issue