From 5ea8e3d6d1b7ddd83cbbd2e68c919aca51c8db6a Mon Sep 17 00:00:00 2001 From: chirac Date: Sun, 24 Jan 2021 14:19:42 +0100 Subject: [PATCH] fix: the function all_ap_in doesn't crash anymore on dormitory use --- topologie/models.py | 12 ++++++------ topologie/views.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/topologie/models.py b/topologie/models.py index b7219d27..faecf380 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -129,17 +129,17 @@ class AccessPoint(Machine): return str(self.interface_set.first().domain.name) @classmethod - def all_ap_in(cls, building_instance): - """Get all the APs of the given building. + def all_ap_in(cls, building_set): + """Get all the APs of the given building set. Args: - building_instance: the building used to find APs. + building_set: the building set used to find APs. Returns: - The queryset of all APs in the given building. + The queryset of all APs in the given building set. """ return cls.objects.filter( - interface__port__switch__switchbay__building=building_instance + interface__port__switch__switchbay__building__in=building_set ) def __str__(self): @@ -770,7 +770,7 @@ class Building(AclMixin, RevMixin, models.Model): def all_ap_in(self): """Get all the APs in the building.""" - return AccessPoint.all_ap_in(self) + return AccessPoint.all_ap_in(Building.objects.filter(id=self.id)) def get_name(self): if Dormitory.is_multiple_dorms(): diff --git a/topologie/views.py b/topologie/views.py index 93c21d0e..cddfa28e 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -1331,7 +1331,7 @@ def make_machine_graph(): {"numero": port.port, "related": port.related.switch.get_name} ) - for ap in AccessPoint.all_ap_in(building).prefetch_related( + for ap in building.all_ap_in().prefetch_related( Prefetch( "interface_set", queryset=(