From 3ac380271952a2e5b2e6b73a762f554b42912816 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 17 Mar 2022 18:09:08 +0100 Subject: [PATCH] Filter for show only dhid tags --- ereuse_devicehub/inventory/forms.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 3faa8751..7108e3a5 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -1019,6 +1019,18 @@ class PrintTagsForm(FlaskForm): return False device_ids = self.devices.data.split(",") - self._tags = Tag.query.filter(Tag.device_id.in_(device_ids)).all() + self._devices = ( + Device.query.filter(Device.id.in_(device_ids)) + .filter(Device.owner_id == g.user.id) + .distinct() + .all() + ) + dhids = [x.devicehub_id for x in self._devices] + # filter for found all tags of a list of devices + # self._tags = Tag.query.filter(Tag.owner_id == g.user.id).filter(Tag.device_id.in_(dhids)).all() + # filter for found all tags equal to devicehub_id + self._tags = ( + Tag.query.filter(Tag.owner_id == g.user.id).filter(Tag.id.in_(dhids)).all() + ) return is_valid