From fd00a3ec34373e16907f25f673db76b52612781b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 5 Jan 2022 16:00:13 +0100 Subject: [PATCH] add view, lot and type in formulary new action --- ereuse_devicehub/inventory/forms.py | 8 ++++++++ ereuse_devicehub/inventory/views.py | 17 ++++++++++++++++- ereuse_devicehub/static/js/main_inventory.js | 2 ++ .../templates/inventory/actions.html | 6 ++++-- .../templates/inventory/device_list.html | 3 ++- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index bfee0d23..00c6afdc 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -86,6 +86,14 @@ class NewActionForm(FlaskForm): ('Warning', 'Warning'), ('Error', 'Error')]) description = TextAreaField(u'Description') + lot = HiddenField() + type = HiddenField() + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.instance = None + if self.lot.data: + self.lot.data = self.lot.data.id def save(self): pass diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 2bf63365..e35f3777 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -30,7 +30,7 @@ class DeviceListView(View): context = {'devices': devices, 'lots': lots, 'form_lot_device': LotDeviceForm(), - 'form_new_action': NewActionForm(), + 'form_new_action': NewActionForm(lot=lot), 'lot': lot} return flask.render_template(self.template_name, **context) @@ -96,7 +96,22 @@ class LotDeleteView(View): return flask.redirect(next_url) +class NewActionView(View): + methods = ['POST'] + decorators = [login_required] + def dispatch_request(self): + form = NewActionForm() + # import pdb; pdb.set_trace() + # from flask import request + if form.validate_on_submit(): + form.save() + + next_url = url_for('inventory.devices.devicelist') + return flask.redirect(next_url) + + +devices.add_url_rule('/action/add/', view_func=NewActionView.as_view('action_add')) 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')) diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 12a12bae..7cfa0de6 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -35,4 +35,6 @@ function deviceSelect() { function newAction(action) { console.log(action); + $("#actionModal #type").val(action); + $("#activeActionModal").click(); } diff --git a/ereuse_devicehub/templates/inventory/actions.html b/ereuse_devicehub/templates/inventory/actions.html index 4e8151da..1a2d60f9 100644 --- a/ereuse_devicehub/templates/inventory/actions.html +++ b/ereuse_devicehub/templates/inventory/actions.html @@ -7,7 +7,7 @@ -
+ {{ form_new_action.csrf_token }}