refactoring and put again the lot in form of actions

This commit is contained in:
Cayo Puigdefabregas 2022-02-04 12:10:27 +01:00
parent f011e29ce9
commit 662f75bb7b
4 changed files with 17 additions and 12 deletions

View File

@ -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):

View File

@ -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/<string:lot_id>/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/<string:id>/', view_func=DeviceDetailView.as_view('device_details'))
devices.add_url_rule('/lot/<string:lot_id>/device/', view_func=DeviceListView.as_view('lotdevicelist'))

View File

@ -21,8 +21,10 @@
</p>
<p class="enumeration-devices"></p>
</div>
{% elif field == form_new_action.lot %}
{{ field }}
{% elif field == form_new_action.type %}
{{ field(class_="form-control") }}
{{ field }}
{% else %}
<div class="col-12">
{{ field.label(class_="form-label") }}

View File

@ -8,12 +8,7 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="
{% if lot %}
{{ url_for('inventory.devices.lot_allocate_add', lot_id=lot.id) }}
{% else %}
{{ url_for('inventory.devices.allocate_add') }}
{% endif %}" method="post">
<form action="{{ url_for('inventory.devices.allocate_add') }}" method="post">
{{ form_new_allocate.csrf_token }}
<div class="modal-body">
<p class="text-danger" id="pol" style="display: none;">
@ -30,8 +25,10 @@
</p>
<p class="enumeration-devices"></p>
</div>
{% elif field == form_new_allocate.lot %}
{{ field }}
{% elif field == form_new_allocate.type %}
{{ field(class_="form-control") }}
{{ field }}
{% else %}
<div class="col-12">
{{ field.label(class_="form-label") }}