From d994cd2f1053b6aa5dfcf8d29ef89265cefc783f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 3 Jan 2022 12:28:42 +0100 Subject: [PATCH] remove lot --- ereuse_devicehub/inventory/forms.py | 5 +++++ ereuse_devicehub/inventory/views.py | 16 +++++++++++++++- .../templates/inventory/device_list.html | 8 ++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 722509f4..8654e76e 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -64,3 +64,8 @@ class LotForm(FlaskForm): db.session.add(self.lot) db.session.commit() + + def remove(self): + if self.lot and not self.lot.devices: + self.lot.delete() + db.session.commit() diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 6a6fc37e..4be3b992 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -80,9 +80,23 @@ class LotView(View): return flask.render_template(self.template_name, form=form, title=self.title) +class LotDeleteView(View): + methods = ['GET'] + decorators = [login_required] + template_name = 'inventory/device_list.html' + + def dispatch_request(self, id): + form = LotForm(id=id) + form.remove() + next_url = url_for('inventory.devices.devicelist') + return flask.redirect(next_url) + + + devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist')) devices.add_url_rule('/lot//device/', view_func=DeviceListView.as_view('lotdevicelist')) devices.add_url_rule('/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add')) devices.add_url_rule('/lot/devices/del/', view_func=LotDeviceDeleteView.as_view('lot_devices_del')) -devices.add_url_rule('/lot/add', view_func=LotView.as_view('lot_add')) +devices.add_url_rule('/lot/add/', view_func=LotView.as_view('lot_add')) +devices.add_url_rule('/lot//del/', view_func=LotDeleteView.as_view('lot_del')) devices.add_url_rule('/lot//', view_func=LotView.as_view('lot_edit')) diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 04ba7033..e104a5ce 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -33,11 +33,19 @@