From 71f5a8a98b20d110ef9862905fe20b13ec153ba4 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 2 Feb 2022 13:51:54 +0100 Subject: [PATCH] fix doble query --- ereuse_devicehub/inventory/forms.py | 16 ++++++++-------- ereuse_devicehub/inventory/views.py | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 875f5c76..83efbd89 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -418,7 +418,6 @@ class TagDeviceForm(FlaskForm): self.delete = kwargs.pop('delete', None) self.device_id = kwargs.pop('device', None) - # import pdb; pdb.set_trace() super().__init__(*args, **kwargs) if self.delete: @@ -479,12 +478,13 @@ class NewActionForm(FlaskForm): if not is_valid: return False - devices = set(self.devices.data.split(",")) - self._devices = OrderedSet(Device.query.filter(Device.id.in_(devices)).filter( - Device.owner_id == g.user.id).all()) + if self.devices.data: + devices = set(self.devices.data.split(",")) + self._devices = OrderedSet(Device.query.filter(Device.id.in_(devices)).filter( + Device.owner_id == g.user.id).all()) - if not self._devices: - return False + if not self._devices: + return False return True @@ -497,12 +497,12 @@ class NewActionForm(FlaskForm): self.severity.data = Severity[self.severity.data] self.populate_obj(self.instance) + db.session.add(self.instance) + db.session.commit() self.devices.data = devices self.severity.data = severity - db.session.add(self.instance) - db.session.commit() return self.instance diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index d908e501..ea17d25f 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -297,11 +297,12 @@ class NewAllocateView(NewActionView, DeviceListMix): def dispatch_request(self): dispatch = super().dispatch_request() - if self.form.validate_on_submit(): + if dispatch.status_code == 302: return dispatch # lot_id = self.form.lot.data # FIXME + # import pdb; pdb.set_trace() self.get_context(None) return flask.render_template(self.template_name, **self.context)