From 1961e3d408fbb9d42cc9403bed173845d2eb1b67 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 2 Aug 2021 18:17:08 +0200 Subject: [PATCH] rebuild query for filter devs without lots --- ereuse_devicehub/resources/device/views.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 20982430..b046b49d 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -86,6 +86,7 @@ class DeviceView(View): filter = f.Nested(Filters, missing=[]) sort = f.Nested(Sorting, missing=[Device.id.asc()]) page = f.Integer(validate=v.Range(min=1), missing=1) + unassign = f.Integer(validate=v.Range(min=0, max=1), missing=0) def get(self, id): """Devices view @@ -161,6 +162,7 @@ class DeviceView(View): (Device.owner_id == g.user.id) | (Device.id.in_(trades_dev_ids)) ).distinct() + unassign = args.get('unassign', None) search_p = args.get('search', None) if search_p: properties = DeviceSearch.properties @@ -175,6 +177,11 @@ class DeviceView(View): search.Search.rank(tags, search_p) + search.Search.rank(devicehub_ids, search_p) ) + if unassign: + subquery = LotDeviceDescendants.query.with_entities( + LotDeviceDescendants.device_id + ) + query = query.filter(Device.id.notin_(subquery)) return query.filter(*args['filter']).order_by(*args['sort'])