Better linter score on topologie
This commit is contained in:
parent
2b6131ecec
commit
8796d01608
6 changed files with 58 additions and 80 deletions
|
@ -47,68 +47,46 @@ from .models import (
|
||||||
class StackAdmin(VersionAdmin):
|
class StackAdmin(VersionAdmin):
|
||||||
"""Admin class of stacks (includes switches)."""
|
"""Admin class of stacks (includes switches)."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class SwitchAdmin(VersionAdmin):
|
class SwitchAdmin(VersionAdmin):
|
||||||
"""Admin class of switches."""
|
"""Admin class of switches."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class PortAdmin(VersionAdmin):
|
class PortAdmin(VersionAdmin):
|
||||||
"""Admin class of switch ports."""
|
"""Admin class of switch ports."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class AccessPointAdmin(VersionAdmin):
|
class AccessPointAdmin(VersionAdmin):
|
||||||
"""Admin class of APs."""
|
"""Admin class of APs."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class RoomAdmin(VersionAdmin):
|
class RoomAdmin(VersionAdmin):
|
||||||
"""Admin class of rooms."""
|
"""Admin class of rooms."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ModelSwitchAdmin(VersionAdmin):
|
class ModelSwitchAdmin(VersionAdmin):
|
||||||
"""Admin class of switch models."""
|
"""Admin class of switch models."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ConstructorSwitchAdmin(VersionAdmin):
|
class ConstructorSwitchAdmin(VersionAdmin):
|
||||||
"""Admin class of switch constructors."""
|
"""Admin class of switch constructors."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class SwitchBayAdmin(VersionAdmin):
|
class SwitchBayAdmin(VersionAdmin):
|
||||||
"""Admin class of switch bays."""
|
"""Admin class of switch bays."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class BuildingAdmin(VersionAdmin):
|
class BuildingAdmin(VersionAdmin):
|
||||||
"""Admin class of buildings."""
|
"""Admin class of buildings."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class DormitoryAdmin(VersionAdmin):
|
class DormitoryAdmin(VersionAdmin):
|
||||||
"""Admin class of dormitories."""
|
"""Admin class of dormitories."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class PortProfileAdmin(VersionAdmin):
|
class PortProfileAdmin(VersionAdmin):
|
||||||
"""Admin class of port profiles."""
|
"""Admin class of port profiles."""
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Port, PortAdmin)
|
admin.site.register(Port, PortAdmin)
|
||||||
admin.site.register(AccessPoint, AccessPointAdmin)
|
admin.site.register(AccessPoint, AccessPointAdmin)
|
||||||
|
|
|
@ -23,7 +23,7 @@ from rest_framework import serializers
|
||||||
|
|
||||||
import machines.models as machines
|
import machines.models as machines
|
||||||
import topologie.models as topologie
|
import topologie.models as topologie
|
||||||
from api.serializers import NamespacedHIField, NamespacedHMSerializer, NamespacedHRField
|
from api.serializers import NamespacedHMSerializer
|
||||||
from machines.api.serializers import Ipv6ListSerializer, VlanSerializer
|
from machines.api.serializers import Ipv6ListSerializer, VlanSerializer
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -77,14 +77,15 @@ class PortForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(PortForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class EditPortForm(FormRevMixin, ModelForm):
|
class EditPortForm(FormRevMixin, ModelForm):
|
||||||
"""Form used to edit a switch's port: change in RADIUS or VLANs settings,
|
"""Form used to edit a switch's port: change in RADIUS or VLANs settings,
|
||||||
assignement to a room, port or machine.
|
assignement to a room, port or machine.
|
||||||
|
|
||||||
A port is related to either a room, another port (uplink) or a machine (server or AP).
|
A port is related to either a room, another port (uplink)
|
||||||
|
or a machine (server or AP).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Meta(PortForm.Meta):
|
class Meta(PortForm.Meta):
|
||||||
|
@ -99,7 +100,7 @@ class EditPortForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(EditPortForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields["machine_interface"].queryset = (
|
self.fields["machine_interface"].queryset = (
|
||||||
Interface.objects.all().select_related("domain__extension")
|
Interface.objects.all().select_related("domain__extension")
|
||||||
)
|
)
|
||||||
|
@ -127,7 +128,7 @@ class AddPortForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(AddPortForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields["machine_interface"].queryset = (
|
self.fields["machine_interface"].queryset = (
|
||||||
Interface.objects.all().select_related("domain__extension")
|
Interface.objects.all().select_related("domain__extension")
|
||||||
)
|
)
|
||||||
|
@ -152,7 +153,7 @@ class StackForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(StackForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class AddAccessPointForm(NewMachineForm):
|
class AddAccessPointForm(NewMachineForm):
|
||||||
|
@ -204,7 +205,7 @@ class EditRoomForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(EditRoomForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class CreatePortsForm(forms.Form):
|
class CreatePortsForm(forms.Form):
|
||||||
|
@ -229,7 +230,7 @@ class EditModelSwitchForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(EditModelSwitchForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
instance = kwargs.get("instance", None)
|
instance = kwargs.get("instance", None)
|
||||||
if instance:
|
if instance:
|
||||||
self.initial["members"] = Switch.objects.filter(model=instance)
|
self.initial["members"] = Switch.objects.filter(model=instance)
|
||||||
|
@ -249,7 +250,7 @@ class EditConstructorSwitchForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(EditConstructorSwitchForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class EditSwitchBayForm(FormRevMixin, ModelForm):
|
class EditSwitchBayForm(FormRevMixin, ModelForm):
|
||||||
|
@ -270,7 +271,7 @@ class EditSwitchBayForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(EditSwitchBayForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
instance = kwargs.get("instance", None)
|
instance = kwargs.get("instance", None)
|
||||||
if instance:
|
if instance:
|
||||||
self.initial["members"] = Switch.objects.filter(switchbay=instance)
|
self.initial["members"] = Switch.objects.filter(switchbay=instance)
|
||||||
|
@ -290,7 +291,7 @@ class EditBuildingForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(EditBuildingForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class EditDormitoryForm(FormRevMixin, ModelForm):
|
class EditDormitoryForm(FormRevMixin, ModelForm):
|
||||||
|
@ -302,7 +303,7 @@ class EditDormitoryForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(EditDormitoryForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class EditPortProfileForm(FormRevMixin, ModelForm):
|
class EditPortProfileForm(FormRevMixin, ModelForm):
|
||||||
|
@ -320,7 +321,7 @@ class EditPortProfileForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(EditPortProfileForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class EditModuleForm(FormRevMixin, ModelForm):
|
class EditModuleForm(FormRevMixin, ModelForm):
|
||||||
|
@ -332,7 +333,7 @@ class EditModuleForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(EditModuleForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class EditSwitchModuleForm(FormRevMixin, ModelForm):
|
class EditSwitchModuleForm(FormRevMixin, ModelForm):
|
||||||
|
@ -344,4 +345,4 @@ class EditSwitchModuleForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
prefix = kwargs.pop("prefix", self.Meta.model.__name__)
|
||||||
super(EditSwitchModuleForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super().__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
|
@ -34,11 +34,9 @@ The following models are defined:
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import itertools
|
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import IntegrityError, models, transaction
|
from django.db import models, transaction
|
||||||
from django.db.models.signals import post_delete, post_save
|
from django.db.models.signals import post_delete, post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
@ -78,7 +76,7 @@ class Stack(AclMixin, RevMixin, models.Model):
|
||||||
self.clean()
|
self.clean()
|
||||||
if not self.name:
|
if not self.name:
|
||||||
self.name = self.stack_id
|
self.name = self.stack_id
|
||||||
super(Stack, self).save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""Check if id_max < id_min."""
|
"""Check if id_max < id_min."""
|
||||||
|
@ -143,7 +141,8 @@ class AccessPoint(Machine):
|
||||||
|
|
||||||
# We want to retrieve the default behaviour given by AclMixin rather
|
# We want to retrieve the default behaviour given by AclMixin rather
|
||||||
# than the one overwritten by Machine. If you are not familiar with
|
# than the one overwritten by Machine. If you are not familiar with
|
||||||
# the behaviour of `super`, please check https://docs.python.org/3/library/functions.html#super
|
# the behaviour of `super`, please check
|
||||||
|
# https://docs.python.org/3/library/functions.html#super
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, *args, **kwargs):
|
def get_instance(cls, *args, **kwargs):
|
||||||
|
@ -208,7 +207,8 @@ class Server(Machine):
|
||||||
|
|
||||||
# We want to retrieve the default behaviour given by AclMixin rather
|
# We want to retrieve the default behaviour given by AclMixin rather
|
||||||
# than the one overwritten by Machine. If you are not familiar with
|
# than the one overwritten by Machine. If you are not familiar with
|
||||||
# the behaviour of `super`, please check https://docs.python.org/3/library/functions.html#super
|
# the behaviour of `super`, please check
|
||||||
|
# https://docs.python.org/3/library/functions.html#super
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, *args, **kwargs):
|
def get_instance(cls, *args, **kwargs):
|
||||||
|
@ -285,7 +285,7 @@ class Switch(Machine):
|
||||||
"""Check if the stack member ID is in the range of the stack's IDs and
|
"""Check if the stack member ID is in the range of the stack's IDs and
|
||||||
calls the clean of the parent class.
|
calls the clean of the parent class.
|
||||||
"""
|
"""
|
||||||
super(Switch, self).clean()
|
super().clean()
|
||||||
if self.stack is not None:
|
if self.stack is not None:
|
||||||
if self.stack_member_id is not None:
|
if self.stack_member_id is not None:
|
||||||
if (self.stack_member_id > self.stack.member_id_max) or (
|
if (self.stack_member_id > self.stack.member_id_max) or (
|
||||||
|
@ -356,7 +356,6 @@ class Switch(Machine):
|
||||||
"""
|
"""
|
||||||
if self.get_radius_key:
|
if self.get_radius_key:
|
||||||
return self.get_radius_key.radius_key
|
return self.get_radius_key.radius_key
|
||||||
else:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
@ -409,7 +408,6 @@ class Switch(Machine):
|
||||||
"id": self.get_management_cred.management_id,
|
"id": self.get_management_cred.management_id,
|
||||||
"pass": self.get_management_cred.management_pass,
|
"pass": self.get_management_cred.management_pass,
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
@ -427,9 +425,8 @@ class Switch(Machine):
|
||||||
)
|
)
|
||||||
if sw_management_ssl:
|
if sw_management_ssl:
|
||||||
return "ssl"
|
return "ssl"
|
||||||
elif sw_management:
|
if sw_management:
|
||||||
return "plain"
|
return "plain"
|
||||||
else:
|
|
||||||
return self.automatic_provision
|
return self.automatic_provision
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
@ -487,7 +484,6 @@ class Switch(Machine):
|
||||||
"""Get the dormitory in which the switch is located."""
|
"""Get the dormitory in which the switch is located."""
|
||||||
if self.switchbay:
|
if self.switchbay:
|
||||||
return self.switchbay.building.dormitory
|
return self.switchbay.building.dormitory
|
||||||
else:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -540,7 +536,8 @@ class Switch(Machine):
|
||||||
|
|
||||||
# We want to retrieve the default behaviour given by AclMixin rather
|
# We want to retrieve the default behaviour given by AclMixin rather
|
||||||
# than the one overwritten by Machine. If you are not familiar with
|
# than the one overwritten by Machine. If you are not familiar with
|
||||||
# the behaviour of `super`, please check https://docs.python.org/3/library/functions.html#super
|
# the behaviour of `super`, please check
|
||||||
|
# https://docs.python.org/3/library/functions.html#super
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_instance(cls, *args, **kwargs):
|
def get_instance(cls, *args, **kwargs):
|
||||||
|
@ -592,7 +589,6 @@ class ModelSwitch(AclMixin, RevMixin, models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.commercial_name:
|
if self.commercial_name:
|
||||||
return str(self.constructor) + " " + str(self.commercial_name)
|
return str(self.constructor) + " " + str(self.commercial_name)
|
||||||
else:
|
|
||||||
return str(self.constructor) + " " + self.reference
|
return str(self.constructor) + " " + self.reference
|
||||||
|
|
||||||
|
|
||||||
|
@ -711,7 +707,6 @@ class Dormitory(AclMixin, RevMixin, models.Model):
|
||||||
multiple_dorms = cache.get("multiple_dorms")
|
multiple_dorms = cache.get("multiple_dorms")
|
||||||
if multiple_dorms:
|
if multiple_dorms:
|
||||||
return multiple_dorms
|
return multiple_dorms
|
||||||
else:
|
|
||||||
return cache.get_or_set("multiple_dorms", cls.objects.count() > 1)
|
return cache.get_or_set("multiple_dorms", cls.objects.count() > 1)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -752,7 +747,6 @@ class Building(AclMixin, RevMixin, models.Model):
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
if Dormitory.is_multiple_dorms():
|
if Dormitory.is_multiple_dorms():
|
||||||
return self.dormitory.name + " : " + self.name
|
return self.dormitory.name + " : " + self.name
|
||||||
else:
|
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -835,11 +829,10 @@ class Port(AclMixin, RevMixin, models.Model):
|
||||||
"""More elaborated name for label on switch configuration."""
|
"""More elaborated name for label on switch configuration."""
|
||||||
if self.related:
|
if self.related:
|
||||||
return _("Uplink: ") + self.related.switch.short_name
|
return _("Uplink: ") + self.related.switch.short_name
|
||||||
elif self.machine_interface:
|
if self.machine_interface:
|
||||||
return _("Machine: ") + str(self.machine_interface.domain)
|
return _("Machine: ") + str(self.machine_interface.domain)
|
||||||
elif self.room:
|
if self.room:
|
||||||
return _("Room: ") + str(self.room)
|
return _("Room: ") + str(self.room)
|
||||||
else:
|
|
||||||
return _("Unknown")
|
return _("Unknown")
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
@ -853,16 +846,14 @@ class Port(AclMixin, RevMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
if self.custom_profile:
|
if self.custom_profile:
|
||||||
return self.custom_profile
|
return self.custom_profile
|
||||||
elif self.related:
|
if self.related:
|
||||||
return self.switch.default_uplink_profile
|
return self.switch.default_uplink_profile
|
||||||
elif self.machine_interface:
|
if self.machine_interface:
|
||||||
if hasattr(self.machine_interface.machine, "accesspoint"):
|
if hasattr(self.machine_interface.machine, "accesspoint"):
|
||||||
return self.switch.default_access_point_profile
|
return self.switch.default_access_point_profile
|
||||||
else:
|
|
||||||
return self.switch.default_asso_machine_profile
|
return self.switch.default_asso_machine_profile
|
||||||
elif self.room:
|
if self.room:
|
||||||
return self.switch.default_room_profile
|
return self.switch.default_room_profile
|
||||||
else:
|
|
||||||
return Switch.nothing_profile()
|
return Switch.nothing_profile()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -922,7 +913,6 @@ class Port(AclMixin, RevMixin, models.Model):
|
||||||
" before creating the relation."
|
" before creating the relation."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
self.make_port_related()
|
self.make_port_related()
|
||||||
elif hasattr(self, "related_port"):
|
elif hasattr(self, "related_port"):
|
||||||
self.clean_port_related()
|
self.clean_port_related()
|
||||||
|
@ -1117,7 +1107,7 @@ class PortProfile(AclMixin, RevMixin, models.Model):
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""Check that there is only one generic profile default."""
|
"""Check that there is only one generic profile default."""
|
||||||
super(PortProfile, self).clean()
|
super().clean()
|
||||||
if (
|
if (
|
||||||
self.profil_default
|
self.profil_default
|
||||||
and not self.on_dormitory
|
and not self.on_dormitory
|
||||||
|
@ -1129,7 +1119,8 @@ class PortProfile(AclMixin, RevMixin, models.Model):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
{
|
{
|
||||||
"profil_default": _(
|
"profil_default": _(
|
||||||
"A default profile for all dormitories of that type already exists."
|
"A default profile for all dormitories of that type "
|
||||||
|
"already exists."
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -1438,8 +1438,10 @@ def recursive_switchs(switch_start, switch_before, detected):
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
switch_start: the switch to begin the visit on.
|
switch_start: the switch to begin the visit on.
|
||||||
switch_before: the switch that you come from. None if switch_start is the first one.
|
switch_before: the switch that you come from.
|
||||||
detected: list of all switches already visited. None if switch_start is the first one.
|
None if switch_start is the first one.
|
||||||
|
detected: list of all switches already visited.
|
||||||
|
None if switch_start is the first one.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A list of all the links found and a list of all the switches visited.
|
A list of all the links found and a list of all the switches visited.
|
||||||
|
|
|
@ -42,9 +42,11 @@ from .models import Building, Dormitory, Port, PortProfile, Room, Switch, Switch
|
||||||
class RoomAutocomplete(AutocompleteLoggedOutViewMixin):
|
class RoomAutocomplete(AutocompleteLoggedOutViewMixin):
|
||||||
obj_type = Room
|
obj_type = Room
|
||||||
|
|
||||||
# Precision on search to add annotations so search behaves more like users expect it to
|
# Precision on search to add annotations so search behaves more like
|
||||||
|
# users expect it to
|
||||||
def filter_results(self):
|
def filter_results(self):
|
||||||
# Suppose we have a dorm named Dorm, a building named B, and rooms from 001 - 999
|
# Suppose we have a dorm named Dorm, a building named B,
|
||||||
|
# and rooms from 001 - 999
|
||||||
# Comments explain what we try to match
|
# Comments explain what we try to match
|
||||||
self.query_set = self.query_set.annotate(
|
self.query_set = self.query_set.annotate(
|
||||||
full_name=Concat(
|
full_name=Concat(
|
||||||
|
@ -70,6 +72,7 @@ class RoomAutocomplete(AutocompleteLoggedOutViewMixin):
|
||||||
), # Match "Dorm : B 001" (see Room's full_name property)
|
), # Match "Dorm : B 001" (see Room's full_name property)
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
|
# pylint: disable=unsupported-binary-operation
|
||||||
if self.q:
|
if self.q:
|
||||||
self.query_set = self.query_set.filter(
|
self.query_set = self.query_set.filter(
|
||||||
Q(full_name__icontains=self.q)
|
Q(full_name__icontains=self.q)
|
||||||
|
@ -109,7 +112,8 @@ class PortAutocomplete(AutocompleteViewMixin):
|
||||||
|
|
||||||
def filter_results(self):
|
def filter_results(self):
|
||||||
# We want to enter the switch name, not just the port number
|
# We want to enter the switch name, not just the port number
|
||||||
# Because we're concatenating a CharField and an Integer, we have to specify the output_field
|
# Because we're concatenating a CharField and an Integer,
|
||||||
|
# Zwe have to specify the output_field
|
||||||
self.query_set = self.query_set.annotate(
|
self.query_set = self.query_set.annotate(
|
||||||
full_name=Concat(
|
full_name=Concat(
|
||||||
"switch__name", Value(" "), "port", output_field=CharField()
|
"switch__name", Value(" "), "port", output_field=CharField()
|
||||||
|
@ -121,6 +125,7 @@ class PortAutocomplete(AutocompleteViewMixin):
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
if self.q:
|
if self.q:
|
||||||
|
# pylint: disable=unsupported-binary-operation
|
||||||
self.query_set = self.query_set.filter(
|
self.query_set = self.query_set.filter(
|
||||||
Q(full_name__icontains=self.q)
|
Q(full_name__icontains=self.q)
|
||||||
| Q(full_name_stuck__icontains=self.q)
|
| Q(full_name_stuck__icontains=self.q)
|
||||||
|
@ -153,6 +158,7 @@ class SwitchBayAutocomplete(AutocompleteViewMixin):
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
if self.q:
|
if self.q:
|
||||||
|
# pylint: disable=unsupported-binary-operation
|
||||||
self.query_set = self.query_set.filter(
|
self.query_set = self.query_set.filter(
|
||||||
Q(full_name__icontains=self.q)
|
Q(full_name__icontains=self.q)
|
||||||
| Q(dorm_name__icontains=self.q)
|
| Q(dorm_name__icontains=self.q)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue