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)