Commit 4a1b97bb authored by Maël Kervella's avatar Maël Kervella

Pylint compliance on topologie

parent 595c6b99
......@@ -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.
This diff is collapsed.
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