@@ -51,6 +51,12 @@ class Meta(OrganizationManagedFilter.Meta):
51
51
model = FloorPlan
52
52
53
53
54
+ class DeviceFloorplanCoordinatesFilter (OrganizationManagedFilter ):
55
+ class Meta (OrganizationManagedFilter .Meta ):
56
+ model = Location
57
+ fields = OrganizationManagedFilter .Meta .fields + ['floorplan__floor' ]
58
+
59
+
54
60
class ListViewPagination (pagination .PageNumberPagination ):
55
61
page_size = 10
56
62
page_size_query_param = 'page_size'
@@ -187,6 +193,38 @@ class GeoJsonLocationList(
187
193
filterset_class = LocationOrganizationFilter
188
194
189
195
196
+ class DeviceFloorplanCoordinatesList (ProtectedAPIMixin , generics .ListAPIView ):
197
+ """
198
+ List coordinates of device floorplan for a given location ID
199
+ """
200
+
201
+ serializer_class = DeviceLocationSerializer
202
+ pagination_class = ListViewPagination
203
+ filter_backends = [filters .DjangoFilterBackend ]
204
+ filterset_class = DeviceFloorplanCoordinatesFilter
205
+ queryset = DeviceLocation .objects .select_related (
206
+ "content_object" , "location" , "floorplan"
207
+ )
208
+
209
+ def get_queryset (self ):
210
+ location_id = self .kwargs .get ('pk' )
211
+ floor = self .request .query_params .get ('floor' )
212
+ queryset = super ().get_queryset ().filter (location_id = location_id )
213
+ if floor :
214
+ queryset = queryset .filter (floorplan__floor = floor )
215
+ return queryset
216
+
217
+ def list (self , request , * args , ** kwargs ):
218
+ queryset = self .get_queryset ()
219
+ serializer = self .get_serializer (queryset , many = True )
220
+ available_floors = queryset .values_list (
221
+ 'floorplan__floor' , flat = True
222
+ ).distinct ()
223
+ return Response (
224
+ {"devices" : serializer .data , "available_floors" : list (available_floors )}
225
+ )
226
+
227
+
190
228
class LocationDeviceList (
191
229
FilterByParentManaged , ProtectedAPIMixin , generics .ListAPIView
192
230
):
@@ -239,6 +277,7 @@ class LocationDetailView(
239
277
# add with_geo filter to device API
240
278
DeviceListCreateView .filterset_class = DeviceListFilter
241
279
280
+ device_floorplan_coordinates = DeviceFloorplanCoordinatesList .as_view ()
242
281
device_coordinates = DeviceCoordinatesView .as_view ()
243
282
device_location = DeviceLocationView .as_view ()
244
283
geojson = GeoJsonLocationList .as_view ()
0 commit comments