From 7a350688eeed6f3bdf8188e3b9d298925dca6df7 Mon Sep 17 00:00:00 2001
From: Helge Jung <hej@c3pb.de>
Date: Thu, 26 Dec 2024 20:26:19 +0100
Subject: [PATCH] c3nav export: publish rooms

---
 src/api/views/maps.py | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/api/views/maps.py b/src/api/views/maps.py
index 77b920960..d38a657fa 100644
--- a/src/api/views/maps.py
+++ b/src/api/views/maps.py
@@ -17,11 +17,13 @@ from api.views.mixins import ConferenceSlugMixin
 _cts = {}  # cache of CoordTransforms (if needed)
 
 
+q_publishable_location_states = Q(location_state__in=[Assembly.LocationState.PREVIEW, Assembly.LocationState.FINAL])
+
+
 def get_exportable_assemblies(conference: Conference) -> QuerySet[Assembly]:
     """Fetches all assemblies in the given conference with publish-able location."""
     exportable_states = [*Assembly.PUBLIC_STATES, Assembly.State.HIDDEN]
-    q_placed_assemblies = Q(location_state__in=[Assembly.LocationState.PREVIEW, Assembly.LocationState.FINAL])
-    return Assembly.objects.filter(conference=conference, state__in=exportable_states).filter(q_placed_assemblies)
+    return Assembly.objects.filter(conference=conference, state__in=exportable_states).filter(q_publishable_location_states)
 
 
 def get_field_geojson(value, srid: int, ct_cache: dict | None = None):
@@ -162,6 +164,7 @@ class C3NavExportView(ConferenceSlugMixin, APIView):
                     'children': get_exportable_assemblies(conference=self.conference).filter(parent=assembly).values_list('slug', flat=True)
                     if assembly.is_cluster
                     else None,
+                    'rooms': assembly.rooms.filter(q_publishable_location_states).exclude(blocked=True).values_list('slug', flat=True),
                     'floor': assembly.get_location_floor_index(),
                     'is_preview': assembly.location_state != Assembly.LocationState.FINAL,
                     'location': loc_data.get('point'),  # assembly.get_location_point_xy(),
@@ -185,6 +188,23 @@ class C3NavExportView(ConferenceSlugMixin, APIView):
                     }
                 )
 
+        for room in self.conference.rooms.filter(q_publishable_location_states).exclude(blocked=True):
+            data.append(
+                {
+                    'type': 'room',
+                    'id': str(room.pk),
+                    'name': room.name,
+                    'is_official': room.is_official,
+                    'in_public_fahrplan': room.is_public_fahrplan,
+                    'description': {'de': room.description_de, 'en': room.description_en},
+                    'public_url': hub_absolute('plainui:room', slug=room.slug, i18n=False),
+                    'is_preview': room.location_state != Assembly.LocationState.FINAL,
+                    'floor': room.get_location_floor_index(),
+                    'location': room.get_location_point_xy(),
+                    'polygons': room.get_location_boundaries_xy(),
+                }
+            )
+
         for poi in self.conference.pois.filter(visible=True):  # type: MapPOI
             data.append(
                 {
-- 
GitLab