From a3909e090dcbd18c98bef5f47cd8a337ad4d3370 Mon Sep 17 00:00:00 2001 From: histausse Date: Tue, 1 Sep 2020 14:01:19 +0200 Subject: [PATCH 1/3] Add building to the room serialiser --- topologie/api/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topologie/api/serializers.py b/topologie/api/serializers.py index 18785ebb..1839fcc8 100644 --- a/topologie/api/serializers.py +++ b/topologie/api/serializers.py @@ -176,7 +176,7 @@ class RoomSerializer(NamespacedHMSerializer): class Meta: model = topologie.Room - fields = ("name", "details", "api_url") + fields = ("name", "building", "details", "api_url") class PortProfileSerializer(NamespacedHMSerializer): From d124203273788d307eca1616a112888806737d04 Mon Sep 17 00:00:00 2001 From: histausse Date: Tue, 1 Sep 2020 16:03:34 +0200 Subject: [PATCH 2/3] Add dormitory to the building serialiser --- topologie/api/serializers.py | 8 +++++++- topologie/api/urls.py | 1 + topologie/api/views.py | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/topologie/api/serializers.py b/topologie/api/serializers.py index 1839fcc8..ce03a842 100644 --- a/topologie/api/serializers.py +++ b/topologie/api/serializers.py @@ -115,8 +115,14 @@ class BuildingSerializer(NamespacedHMSerializer): class Meta: model = topologie.Building - fields = ("name", "api_url") + fields = ("name", "dormitory", "api_url") +class DormitorySerializer(NamespacedHMSerializer): + """Serialize `topologie.models.Dormitory` objects + """ + class Meta: + model = topologie.Dormitory + fields = ("name", "api_url") class SwitchPortSerializer(NamespacedHMSerializer): """Serialize `topologie.models.Port` objects diff --git a/topologie/api/urls.py b/topologie/api/urls.py index f6febb95..1cfd2d3e 100644 --- a/topologie/api/urls.py +++ b/topologie/api/urls.py @@ -30,6 +30,7 @@ urls_viewset = [ (r"topologie/constructorswitch", views.ConstructorSwitchViewSet, None), (r"topologie/switchbay", views.SwitchBayViewSet, None), (r"topologie/building", views.BuildingViewSet, None), + (r"topologie/dormitory", views.DormitoryViewSet, None), (r"topologie/switchport", views.SwitchPortViewSet, "switchport"), (r"topologie/portprofile", views.PortProfileViewSet, "portprofile"), (r"topologie/room", views.RoomViewSet, None) diff --git a/topologie/api/views.py b/topologie/api/views.py index 5e937cda..4cdd5470 100644 --- a/topologie/api/views.py +++ b/topologie/api/views.py @@ -114,6 +114,13 @@ class RoomViewSet(viewsets.ReadOnlyModelViewSet): queryset = topologie.Room.objects.all() serializer_class = serializers.RoomSerializer +class DormitoryViewSet(viewsets.ReadOnlyModelViewSet): + """Exposes list and details of `topologie.models.Dormitory` + objects. + """ + + queryset = topologie.Dormitory.objects.all() + serializer_class = serializers.DormitorySerializer class PortProfileViewSet(viewsets.ReadOnlyModelViewSet): """Exposes list and details of `topologie.models.PortProfile` objects. @@ -146,4 +153,4 @@ class RoleView(generics.ListAPIView): """ queryset = machines.Role.objects.all().prefetch_related("servers") - serializer_class = serializers.RoleSerializer \ No newline at end of file + serializer_class = serializers.RoleSerializer From acca782cdb801a09d6af97ffc5ed85dbe8437294 Mon Sep 17 00:00:00 2001 From: histausse Date: Wed, 2 Sep 2020 14:57:08 +0200 Subject: [PATCH 3/3] remove the second port serialiser --- topologie/api/serializers.py | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/topologie/api/serializers.py b/topologie/api/serializers.py index ce03a842..2006708b 100644 --- a/topologie/api/serializers.py +++ b/topologie/api/serializers.py @@ -299,31 +299,3 @@ class PortsSerializer(NamespacedHMSerializer): class Meta: model = topologie.Port fields = ("state", "port", "pretty_name", "get_port_profile") - - -class SwitchPortSerializer(serializers.ModelSerializer): - """Serialize the data about the switches""" - - ports = PortsSerializer(many=True, read_only=True) - model = ModelSwitchSerializer(read_only=True) - switchbay = SwitchBaySerializer(read_only=True) - - class Meta: - model = topologie.Switch - fields = ( - "short_name", - "model", - "switchbay", - "ports", - "ipv4", - "ipv6", - "interfaces_subnet", - "interfaces6_subnet", - "automatic_provision", - "rest_enabled", - "web_management_enabled", - "get_radius_key_value", - "get_management_cred_value", - "get_radius_servers", - "list_modules", - )