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(),)) date = DateField(u'Date', validators=(validators.Optional(),))
severity = SelectField(u'Severity', choices=[(v.name, v.name) for v in Severity]) severity = SelectField(u'Severity', choices=[(v.name, v.name) for v in Severity])
description = TextAreaField(u'Description') description = TextAreaField(u'Description')
lot = HiddenField()
type = HiddenField() type = HiddenField()
def validate(self, extra_validators=None): def validate(self, extra_validators=None):

View file

@ -289,9 +289,14 @@ class NewActionView(View):
def dispatch_request(self): def dispatch_request(self):
self.form = self._form() 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(): if self.form.validate_on_submit():
self.form.save() self.form.save()
next_url = request.referrer or url_for('inventory.devices.devicelist')
return flask.redirect(next_url) return flask.redirect(next_url)
@ -300,11 +305,13 @@ class NewAllocateView(NewActionView, DeviceListMix):
_form = AllocateForm _form = AllocateForm
def dispatch_request(self, lot_id=None): def dispatch_request(self, lot_id=None):
self.form = self._form()
next_url = url_for('inventory.devices.devicelist') next_url = url_for('inventory.devices.devicelist')
lot_id = self.form.lot.data
if lot_id: if lot_id:
next_url = url_for('inventory.devices.lotdevicelist', lot_id=lot_id) next_url = url_for('inventory.devices.lotdevicelist', lot_id=lot_id)
self.form = self._form()
if self.form.validate_on_submit(): if self.form.validate_on_submit():
self.form.save() self.form.save()
return flask.redirect(next_url) 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/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('/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/', view_func=DeviceListView.as_view('devicelist'))
devices.add_url_rule('/device/<string:id>/', view_func=DeviceDetailView.as_view('device_details')) 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')) devices.add_url_rule('/lot/<string:lot_id>/device/', view_func=DeviceListView.as_view('lotdevicelist'))

View file

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