From fd4fc71bf540fbf546821f7245ef314527e86652 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 26 Jan 2022 10:59:13 +0100 Subject: [PATCH] fix id devices in form of add tag in device --- ereuse_devicehub/inventory/forms.py | 24 ++++++++++++++----- .../templates/inventory/removeDevicestag.html | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 2f2dff34..870083a6 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -400,19 +400,20 @@ class TagForm(FlaskForm): db.session.commit() return self.instance + class TagDeviceForm(FlaskForm): tag = SelectField(u'Tag', choices=[]) + device = StringField(u'Device', [validators.Optional()]) def __init__(self, *args, **kwargs): - delete = kwargs.pop('delete', None) - device_id = kwargs.pop('device', None) + self.delete = kwargs.pop('delete', None) + self.device_id = kwargs.pop('device', None) - self._device = Device.query.filter(Device.id == device_id).filter( - Device.owner_id == g.user.id).one() + # import pdb; pdb.set_trace() super().__init__(*args, **kwargs) - if delete: - tags = Tag.query.filter(Tag.owner_id==g.user.id).filter(Tag.device_id==device_id) + if self.delete: + tags = Tag.query.filter(Tag.owner_id==g.user.id).filter(Tag.device_id==self.device_id) else: tags = Tag.query.filter(Tag.owner_id==g.user.id).filter(Tag.device_id==None) @@ -427,6 +428,17 @@ class TagDeviceForm(FlaskForm): self._tag = Tag.query.filter(Tag.id == self.tag.data).filter( Tag.owner_id == g.user.id).one() + if self.device.data: + try: + self.device.data = int(self.device.data.split(',')[-1]) + except: + self.device.data = None + + if self.device_id or self.device.data: + self.device_id = self.device_id or self.device.data + self._device = Device.query.filter(Device.id == self.device_id).filter( + Device.owner_id == g.user.id).one() + return True def save(self): diff --git a/ereuse_devicehub/templates/inventory/removeDevicestag.html b/ereuse_devicehub/templates/inventory/removeDevicestag.html index 893d5a52..bcc9b145 100644 --- a/ereuse_devicehub/templates/inventory/removeDevicestag.html +++ b/ereuse_devicehub/templates/inventory/removeDevicestag.html @@ -49,6 +49,7 @@

{% endif %} +
Cancel