From 662f75bb7bb28f74226608c85ea5c18dffd7a6b1 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 4 Feb 2022 12:10:27 +0100 Subject: [PATCH] refactoring and put again the lot in form of actions --- ereuse_devicehub/inventory/forms.py | 1 + ereuse_devicehub/inventory/views.py | 13 +++++++++---- ereuse_devicehub/templates/inventory/actions.html | 4 +++- ereuse_devicehub/templates/inventory/allocate.html | 11 ++++------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 89c8c835..e9430e63 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -477,6 +477,7 @@ class NewActionForm(FlaskForm): date = DateField(u'Date', validators=(validators.Optional(),)) severity = SelectField(u'Severity', choices=[(v.name, v.name) for v in Severity]) description = TextAreaField(u'Description') + lot = HiddenField() type = HiddenField() def validate(self, extra_validators=None): diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 70dd5e53..83c0a09d 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -289,9 +289,14 @@ class NewActionView(View): def dispatch_request(self): self.form = self._form() + + next_url = url_for('inventory.devices.devicelist') + lot_id = self.form.lot.data + if lot_id: + next_url = url_for('inventory.devices.lotdevicelist', lot_id=lot_id) + if self.form.validate_on_submit(): self.form.save() - next_url = request.referrer or url_for('inventory.devices.devicelist') return flask.redirect(next_url) @@ -300,11 +305,13 @@ class NewAllocateView(NewActionView, DeviceListMix): _form = AllocateForm def dispatch_request(self, lot_id=None): + self.form = self._form() + next_url = url_for('inventory.devices.devicelist') + lot_id = self.form.lot.data if lot_id: next_url = url_for('inventory.devices.lotdevicelist', lot_id=lot_id) - self.form = self._form() if self.form.validate_on_submit(): self.form.save() return flask.redirect(next_url) @@ -316,8 +323,6 @@ class NewAllocateView(NewActionView, DeviceListMix): devices.add_url_rule('/action/add/', view_func=NewActionView.as_view('action_add')) devices.add_url_rule('/action/allocate/add/', view_func=NewAllocateView.as_view('allocate_add')) -devices.add_url_rule('/lot//action/allocate/add/', - view_func=NewAllocateView.as_view('lot_allocate_add')) devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist')) devices.add_url_rule('/device//', view_func=DeviceDetailView.as_view('device_details')) devices.add_url_rule('/lot//device/', view_func=DeviceListView.as_view('lotdevicelist')) diff --git a/ereuse_devicehub/templates/inventory/actions.html b/ereuse_devicehub/templates/inventory/actions.html index e66d46cc..14230437 100644 --- a/ereuse_devicehub/templates/inventory/actions.html +++ b/ereuse_devicehub/templates/inventory/actions.html @@ -21,8 +21,10 @@

+ {% elif field == form_new_action.lot %} + {{ field }} {% elif field == form_new_action.type %} - {{ field(class_="form-control") }} + {{ field }} {% else %}
{{ field.label(class_="form-label") }} diff --git a/ereuse_devicehub/templates/inventory/allocate.html b/ereuse_devicehub/templates/inventory/allocate.html index a51c3d6a..71bfc0b6 100644 --- a/ereuse_devicehub/templates/inventory/allocate.html +++ b/ereuse_devicehub/templates/inventory/allocate.html @@ -8,12 +8,7 @@
-
+ {{ form_new_allocate.csrf_token }} + {% elif field == form_new_allocate.lot %} + {{ field }} {% elif field == form_new_allocate.type %} - {{ field(class_="form-control") }} + {{ field }} {% else %}
{{ field.label(class_="form-label") }}