From 6a6c0e5182db3addaa3f42b8c199a6c1e1261f0e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 18 Jul 2022 10:07:37 +0200 Subject: [PATCH] show a error message creating placeholder device --- ereuse_devicehub/inventory/views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 52a1a04a..649cb0ca 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -261,10 +261,13 @@ class DeviceCreateView(GenericMixin): next_url = url_for('inventory.devicelist') if lot_id: next_url = url_for('inventory.lotdevicelist', lot_id=lot_id) - lots = self.context['lots'] - lot = lots.filter(Lot.id == lot_id).one() - lot.devices.add(snapshot.device) - db.session.add(lot) + if snapshot and snapshot.device: + lots = self.context['lots'] + lot = lots.filter(Lot.id == lot_id).one() + lot.devices.add(snapshot.device) + db.session.add(lot) + else: + messages.error('Sorry, the device could not be created') db.session.commit() messages.success('Device "{}" created successfully!'.format(form.type.data))