mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-22 23:13:46 +00:00
Pylint compliance on topologie
This commit is contained in:
parent
595c6b99fa
commit
4a1b97bbe3
5 changed files with 118 additions and 102 deletions
|
@ -20,5 +20,9 @@
|
|||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
"""topologie
|
||||
The app in charge of handling all the informations about the network
|
||||
topology like the switches, the rooms, how are the connections, ...
|
||||
"""
|
||||
|
||||
from .acl import *
|
||||
|
|
|
@ -32,15 +32,17 @@ NewSwitchForm)
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import forms
|
||||
from django.forms import ModelForm
|
||||
from django.db.models import Prefetch
|
||||
|
||||
from machines.models import Interface
|
||||
from machines.forms import (
|
||||
EditInterfaceForm,
|
||||
EditMachineForm,
|
||||
NewMachineForm
|
||||
)
|
||||
from django import forms
|
||||
from django.forms import ModelForm, Form
|
||||
from django.db.models import Prefetch
|
||||
from re2o.mixins import FormRevMixin
|
||||
|
||||
from .models import (
|
||||
Port,
|
||||
Switch,
|
||||
|
@ -52,7 +54,6 @@ from .models import (
|
|||
SwitchBay,
|
||||
Building,
|
||||
)
|
||||
from re2o.mixins import FormRevMixin
|
||||
|
||||
|
||||
class PortForm(FormRevMixin, ModelForm):
|
||||
|
|
|
@ -47,7 +47,7 @@ from django.db import IntegrityError
|
|||
from django.db import transaction
|
||||
from reversion import revisions as reversion
|
||||
|
||||
from machines.models import Machine, Interface, regen
|
||||
from machines.models import Machine, regen
|
||||
from re2o.mixins import AclMixin, RevMixin
|
||||
|
||||
|
||||
|
@ -193,6 +193,7 @@ class Switch(AclMixin, Machine):
|
|||
ValidationError("Création d'un port existant.")
|
||||
|
||||
def main_interface(self):
|
||||
""" Returns the 'main' interface of the switch """
|
||||
return self.interface_set.first()
|
||||
|
||||
def __str__(self):
|
||||
|
@ -332,14 +333,15 @@ class Port(AclMixin, RevMixin, models.Model):
|
|||
("view_port", "Peut voir un objet port"),
|
||||
)
|
||||
|
||||
def get_instance(portid, *args, **kwargs):
|
||||
return Port.objects\
|
||||
.select_related('machine_interface__domain__extension')\
|
||||
.select_related('machine_interface__machine__switch')\
|
||||
.select_related('room')\
|
||||
.select_related('related')\
|
||||
.prefetch_related('switch__interface_set__domain__extension')\
|
||||
.get(pk=portid)
|
||||
@classmethod
|
||||
def get_instance(cls, portid, *_args, **kwargs):
|
||||
return (cls.objects
|
||||
.select_related('machine_interface__domain__extension')
|
||||
.select_related('machine_interface__machine__switch')
|
||||
.select_related('room')
|
||||
.select_related('related')
|
||||
.prefetch_related('switch__interface_set__domain__extension')
|
||||
.get(pk=portid))
|
||||
|
||||
def make_port_related(self):
|
||||
""" Synchronise le port distant sur self"""
|
||||
|
@ -364,18 +366,24 @@ class Port(AclMixin, RevMixin, models.Model):
|
|||
cohérence"""
|
||||
if hasattr(self, 'switch'):
|
||||
if self.port > self.switch.number:
|
||||
raise ValidationError("Ce port ne peut exister,\
|
||||
numero trop élevé")
|
||||
if self.room and self.machine_interface or self.room and\
|
||||
self.related or self.machine_interface and self.related:
|
||||
raise ValidationError("Chambre, interface et related_port sont\
|
||||
mutuellement exclusifs")
|
||||
raise ValidationError(
|
||||
"Ce port ne peut exister, numero trop élevé"
|
||||
)
|
||||
if (self.room and self.machine_interface or
|
||||
self.room and self.related or
|
||||
self.machine_interface and self.related):
|
||||
raise ValidationError(
|
||||
"Chambre, interface et related_port sont mutuellement "
|
||||
"exclusifs"
|
||||
)
|
||||
if self.related == self:
|
||||
raise ValidationError("On ne peut relier un port à lui même")
|
||||
if self.related and not self.related.related:
|
||||
if self.related.machine_interface or self.related.room:
|
||||
raise ValidationError("Le port relié est déjà occupé, veuillez\
|
||||
le libérer avant de créer une relation")
|
||||
raise ValidationError(
|
||||
"Le port relié est déjà occupé, veuillez le libérer "
|
||||
"avant de créer une relation"
|
||||
)
|
||||
else:
|
||||
self.make_port_related()
|
||||
elif hasattr(self, 'related_port'):
|
||||
|
@ -403,18 +411,18 @@ class Room(AclMixin, RevMixin, models.Model):
|
|||
|
||||
|
||||
@receiver(post_save, sender=AccessPoint)
|
||||
def ap_post_save(sender, **kwargs):
|
||||
def ap_post_save(_sender, **_kwargs):
|
||||
"""Regeneration des noms des bornes vers le controleur"""
|
||||
regen('unifi-ap-names')
|
||||
|
||||
|
||||
@receiver(post_delete, sender=AccessPoint)
|
||||
def ap_post_delete(sender, **kwargs):
|
||||
def ap_post_delete(_sender, **_kwargs):
|
||||
"""Regeneration des noms des bornes vers le controleur"""
|
||||
regen('unifi-ap-names')
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Stack)
|
||||
def stack_post_delete(sender, **kwargs):
|
||||
def stack_post_delete(_sender, **_kwargs):
|
||||
"""Vide les id des switches membres d'une stack supprimée"""
|
||||
Switch.objects.filter(stack=None).update(stack_member_id=None)
|
||||
|
|
|
@ -19,7 +19,10 @@
|
|||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
"""topologie.tests
|
||||
The tests for the Topologie module.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
# from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
|
|
@ -38,36 +38,11 @@ from __future__ import unicode_literals
|
|||
from django.urls import reverse
|
||||
from django.shortcuts import render, redirect
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db import IntegrityError
|
||||
from django.db import transaction
|
||||
from django.db.models import ProtectedError, Prefetch
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from topologie.models import (
|
||||
Switch,
|
||||
Port,
|
||||
Room,
|
||||
Stack,
|
||||
ModelSwitch,
|
||||
ConstructorSwitch,
|
||||
AccessPoint,
|
||||
SwitchBay,
|
||||
Building
|
||||
)
|
||||
from topologie.forms import EditPortForm, NewSwitchForm, EditSwitchForm
|
||||
from topologie.forms import (
|
||||
AddPortForm,
|
||||
EditRoomForm,
|
||||
StackForm,
|
||||
EditModelSwitchForm,
|
||||
EditConstructorSwitchForm,
|
||||
CreatePortsForm,
|
||||
AddAccessPointForm,
|
||||
EditAccessPointForm,
|
||||
EditSwitchBayForm,
|
||||
EditBuildingForm
|
||||
)
|
||||
from users.views import form
|
||||
from re2o.utils import re2o_paginator, SortTable
|
||||
from re2o.acl import (
|
||||
|
@ -79,8 +54,6 @@ from re2o.acl import (
|
|||
)
|
||||
from machines.forms import (
|
||||
DomainForm,
|
||||
NewMachineForm,
|
||||
EditMachineForm,
|
||||
EditInterfaceForm,
|
||||
AddInterfaceForm
|
||||
)
|
||||
|
@ -88,6 +61,33 @@ from machines.views import generate_ipv4_mbf_param
|
|||
from machines.models import Interface
|
||||
from preferences.models import AssoOption, GeneralOption
|
||||
|
||||
from .models import (
|
||||
Switch,
|
||||
Port,
|
||||
Room,
|
||||
Stack,
|
||||
ModelSwitch,
|
||||
ConstructorSwitch,
|
||||
AccessPoint,
|
||||
SwitchBay,
|
||||
Building
|
||||
)
|
||||
from .forms import (
|
||||
EditPortForm,
|
||||
NewSwitchForm,
|
||||
EditSwitchForm,
|
||||
AddPortForm,
|
||||
EditRoomForm,
|
||||
StackForm,
|
||||
EditModelSwitchForm,
|
||||
EditConstructorSwitchForm,
|
||||
CreatePortsForm,
|
||||
AddAccessPointForm,
|
||||
EditAccessPointForm,
|
||||
EditSwitchBayForm,
|
||||
EditBuildingForm
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_view_all(Switch)
|
||||
|
@ -296,7 +296,7 @@ def new_port(request, switchid):
|
|||
|
||||
@login_required
|
||||
@can_edit(Port)
|
||||
def edit_port(request, port_object, portid):
|
||||
def edit_port(request, port_object, _portid):
|
||||
""" Edition d'un port. Permet de changer le switch parent et
|
||||
l'affectation du port"""
|
||||
|
||||
|
@ -322,7 +322,7 @@ def edit_port(request, port_object, portid):
|
|||
|
||||
@login_required
|
||||
@can_delete(Port)
|
||||
def del_port(request, port, portid):
|
||||
def del_port(request, port, _portid):
|
||||
""" Supprime le port"""
|
||||
if request.method == "POST":
|
||||
try:
|
||||
|
@ -358,7 +358,7 @@ def new_stack(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(Stack)
|
||||
def edit_stack(request, stack, stackid):
|
||||
def edit_stack(request, stack, _stackid):
|
||||
"""Edition d'un stack (nombre de switches, nom...)"""
|
||||
stack = StackForm(request.POST or None, instance=stack)
|
||||
if stack.is_valid():
|
||||
|
@ -374,7 +374,7 @@ def edit_stack(request, stack, stackid):
|
|||
|
||||
@login_required
|
||||
@can_delete(Stack)
|
||||
def del_stack(request, stack, stackid):
|
||||
def del_stack(request, stack, _stackid):
|
||||
"""Supprime un stack"""
|
||||
if request.method == "POST":
|
||||
try:
|
||||
|
@ -392,7 +392,7 @@ def del_stack(request, stack, stackid):
|
|||
|
||||
@login_required
|
||||
@can_edit(Stack)
|
||||
def edit_switchs_stack(request, stack, stackid):
|
||||
def edit_switchs_stack(request, stack, _stackid):
|
||||
"""Permet d'éditer la liste des switches dans une stack et l'ajouter"""
|
||||
|
||||
if request.method == "POST":
|
||||
|
@ -429,17 +429,17 @@ def new_switch(request):
|
|||
"créer ou le linker dans preferences")
|
||||
)
|
||||
return redirect(reverse('topologie:index'))
|
||||
new_switch = switch.save(commit=False)
|
||||
new_switch.user = user
|
||||
new_interface_instance = interface.save(commit=False)
|
||||
domain.instance.interface_parent = new_interface_instance
|
||||
new_switch_obj = switch.save(commit=False)
|
||||
new_switch_obj.user = user
|
||||
new_interface_obj = interface.save(commit=False)
|
||||
domain.instance.interface_parent = new_interface_obj
|
||||
if domain.is_valid():
|
||||
new_domain_instance = domain.save(commit=False)
|
||||
new_switch.save()
|
||||
new_interface_instance.machine = new_switch
|
||||
new_interface_instance.save()
|
||||
new_domain_instance.interface_parent = new_interface_instance
|
||||
new_domain_instance.save()
|
||||
new_domain_obj = domain.save(commit=False)
|
||||
new_switch_obj.save()
|
||||
new_interface_obj.machine = new_switch_obj
|
||||
new_interface_obj.save()
|
||||
new_domain_obj.interface_parent = new_interface_obj
|
||||
new_domain_obj.save()
|
||||
messages.success(request, "Le switch a été créé")
|
||||
return redirect(reverse('topologie:index'))
|
||||
i_mbf_param = generate_ipv4_mbf_param(interface, False)
|
||||
|
@ -518,15 +518,15 @@ def edit_switch(request, switch, switchid):
|
|||
instance=switch.interface_set.first().domain
|
||||
)
|
||||
if switch_form.is_valid() and interface_form.is_valid():
|
||||
new_switch = switch_form.save(commit=False)
|
||||
new_interface_instance = interface_form.save(commit=False)
|
||||
new_domain = domain_form.save(commit=False)
|
||||
new_switch_obj = switch_form.save(commit=False)
|
||||
new_interface_obj = interface_form.save(commit=False)
|
||||
new_domain_obj = domain_form.save(commit=False)
|
||||
if switch_form.changed_data:
|
||||
new_switch.save()
|
||||
new_switch_obj.save()
|
||||
if interface_form.changed_data:
|
||||
new_interface_instance.save()
|
||||
new_interface_obj.save()
|
||||
if domain_form.changed_data:
|
||||
new_domain.save()
|
||||
new_domain_obj.save()
|
||||
messages.success(request, "Le switch a bien été modifié")
|
||||
return redirect(reverse('topologie:index'))
|
||||
i_mbf_param = generate_ipv4_mbf_param(interface_form, False)
|
||||
|
@ -570,17 +570,17 @@ def new_ap(request):
|
|||
"créer ou le linker dans preferences")
|
||||
)
|
||||
return redirect(reverse('topologie:index'))
|
||||
new_ap = ap.save(commit=False)
|
||||
new_ap.user = user
|
||||
new_interface = interface.save(commit=False)
|
||||
domain.instance.interface_parent = new_interface
|
||||
new_ap_obj = ap.save(commit=False)
|
||||
new_ap_obj.user = user
|
||||
new_interface_obj = interface.save(commit=False)
|
||||
domain.instance.interface_parent = new_interface_obj
|
||||
if domain.is_valid():
|
||||
new_domain_instance = domain.save(commit=False)
|
||||
new_ap.save()
|
||||
new_interface.machine = new_ap
|
||||
new_interface.save()
|
||||
new_domain_instance.interface_parent = new_interface
|
||||
new_domain_instance.save()
|
||||
new_domain_obj = domain.save(commit=False)
|
||||
new_ap_obj.save()
|
||||
new_interface_obj.machine = new_ap_obj
|
||||
new_interface_obj.save()
|
||||
new_domain_obj.interface_parent = new_interface_obj
|
||||
new_domain_obj.save()
|
||||
messages.success(request, "La borne a été créé")
|
||||
return redirect(reverse('topologie:index-ap'))
|
||||
i_mbf_param = generate_ipv4_mbf_param(interface, False)
|
||||
|
@ -599,7 +599,7 @@ def new_ap(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(AccessPoint)
|
||||
def edit_ap(request, ap, accesspointid):
|
||||
def edit_ap(request, ap, _accesspointid):
|
||||
""" Edition d'un switch. Permet de chambre nombre de ports,
|
||||
place dans le stack, interface et machine associée"""
|
||||
interface_form = EditInterfaceForm(
|
||||
|
@ -625,15 +625,15 @@ def edit_ap(request, ap, accesspointid):
|
|||
"créer ou le linker dans preferences")
|
||||
)
|
||||
return redirect(reverse('topologie:index-ap'))
|
||||
new_ap = ap_form.save(commit=False)
|
||||
new_interface = interface_form.save(commit=False)
|
||||
new_domain = domain_form.save(commit=False)
|
||||
new_ap_obj = ap_form.save(commit=False)
|
||||
new_interface_obj = interface_form.save(commit=False)
|
||||
new_domain_obj = domain_form.save(commit=False)
|
||||
if ap_form.changed_data:
|
||||
new_ap.save()
|
||||
new_ap_obj.save()
|
||||
if interface_form.changed_data:
|
||||
new_interface.save()
|
||||
new_interface_obj.save()
|
||||
if domain_form.changed_data:
|
||||
new_domain.save()
|
||||
new_domain_obj.save()
|
||||
messages.success(request, "La borne a été modifiée")
|
||||
return redirect(reverse('topologie:index-ap'))
|
||||
i_mbf_param = generate_ipv4_mbf_param(interface_form, False)
|
||||
|
@ -668,7 +668,7 @@ def new_room(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(Room)
|
||||
def edit_room(request, room, roomid):
|
||||
def edit_room(request, room, _roomid):
|
||||
""" Edition numero et details de la chambre"""
|
||||
room = EditRoomForm(request.POST or None, instance=room)
|
||||
if room.is_valid():
|
||||
|
@ -685,7 +685,7 @@ def edit_room(request, room, roomid):
|
|||
|
||||
@login_required
|
||||
@can_delete(Room)
|
||||
def del_room(request, room, roomid):
|
||||
def del_room(request, room, _roomid):
|
||||
""" Suppression d'un chambre"""
|
||||
if request.method == "POST":
|
||||
try:
|
||||
|
@ -723,7 +723,7 @@ def new_model_switch(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(ModelSwitch)
|
||||
def edit_model_switch(request, model_switch, modelswitchid):
|
||||
def edit_model_switch(request, model_switch, _modelswitchid):
|
||||
""" Edition d'un modèle de switch"""
|
||||
|
||||
model_switch = EditModelSwitchForm(
|
||||
|
@ -744,7 +744,7 @@ def edit_model_switch(request, model_switch, modelswitchid):
|
|||
|
||||
@login_required
|
||||
@can_delete(ModelSwitch)
|
||||
def del_model_switch(request, model_switch, modelswitchid):
|
||||
def del_model_switch(request, model_switch, _modelswitchid):
|
||||
""" Suppression d'un modèle de switch"""
|
||||
if request.method == "POST":
|
||||
try:
|
||||
|
@ -782,7 +782,7 @@ def new_switch_bay(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(SwitchBay)
|
||||
def edit_switch_bay(request, switch_bay, switchbayid):
|
||||
def edit_switch_bay(request, switch_bay, _switchbayid):
|
||||
""" Edition d'une baie de switch"""
|
||||
switch_bay = EditSwitchBayForm(request.POST or None, instance=switch_bay)
|
||||
if switch_bay.is_valid():
|
||||
|
@ -799,7 +799,7 @@ def edit_switch_bay(request, switch_bay, switchbayid):
|
|||
|
||||
@login_required
|
||||
@can_delete(SwitchBay)
|
||||
def del_switch_bay(request, switch_bay, switchbayid):
|
||||
def del_switch_bay(request, switch_bay, _switchbayid):
|
||||
""" Suppression d'une baie de switch"""
|
||||
if request.method == "POST":
|
||||
try:
|
||||
|
@ -837,7 +837,7 @@ def new_building(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(Building)
|
||||
def edit_building(request, building, buildingid):
|
||||
def edit_building(request, building, _buildingid):
|
||||
""" Edition d'un batiment"""
|
||||
building = EditBuildingForm(request.POST or None, instance=building)
|
||||
if building.is_valid():
|
||||
|
@ -854,7 +854,7 @@ def edit_building(request, building, buildingid):
|
|||
|
||||
@login_required
|
||||
@can_delete(Building)
|
||||
def del_building(request, building, buildingid):
|
||||
def del_building(request, building, _buildingid):
|
||||
""" Suppression d'un batiment"""
|
||||
if request.method == "POST":
|
||||
try:
|
||||
|
@ -892,7 +892,7 @@ def new_constructor_switch(request):
|
|||
|
||||
@login_required
|
||||
@can_edit(ConstructorSwitch)
|
||||
def edit_constructor_switch(request, constructor_switch, constructorswitchid):
|
||||
def edit_constructor_switch(request, constructor_switch, _constructorswitchid):
|
||||
""" Edition d'un constructeur de switch"""
|
||||
|
||||
constructor_switch = EditConstructorSwitchForm(
|
||||
|
@ -913,7 +913,7 @@ def edit_constructor_switch(request, constructor_switch, constructorswitchid):
|
|||
|
||||
@login_required
|
||||
@can_delete(ConstructorSwitch)
|
||||
def del_constructor_switch(request, constructor_switch, constructorswitchid):
|
||||
def del_constructor_switch(request, constructor_switch, _constructorswitchid):
|
||||
""" Suppression d'un constructeur de switch"""
|
||||
if request.method == "POST":
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue