precommit
This commit is contained in:
parent
40abcd6b67
commit
3f7fd1b6ec
|
@ -137,8 +137,15 @@ class FilterForm(FlaskForm):
|
||||||
|
|
||||||
|
|
||||||
class LotDeviceForm(FlaskForm):
|
class LotDeviceForm(FlaskForm):
|
||||||
lot = StringField('Lot', [validators.UUID()])
|
|
||||||
devices = StringField('Devices', [validators.length(min=1)])
|
devices = StringField('Devices', [validators.length(min=1)])
|
||||||
|
lot = SelectField('Lot', choices=[])
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
# TODO
|
||||||
|
self.lot.choices = [
|
||||||
|
(lot.id, lot.name) for lot in Lot.query.filter(Lot.owner_id == g.user.id)
|
||||||
|
]
|
||||||
|
|
||||||
def validate(self, extra_validators=None):
|
def validate(self, extra_validators=None):
|
||||||
is_valid = super().validate(extra_validators)
|
is_valid = super().validate(extra_validators)
|
||||||
|
@ -1046,3 +1053,15 @@ class TradeDocumentForm(FlaskForm):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return self._obj
|
return self._obj
|
||||||
|
|
||||||
|
|
||||||
|
class LotDeviceShowForm(FlaskForm):
|
||||||
|
devices = StringField(render_kw={'class': "devicesList"})
|
||||||
|
|
||||||
|
def validate(self, extra_validators=None):
|
||||||
|
is_valid = super().validate(extra_validators)
|
||||||
|
|
||||||
|
device_ids = self.devices.data.split(",")
|
||||||
|
self._devices = Device.query.filter(Device.id.in_(device_ids)).all()
|
||||||
|
|
||||||
|
return is_valid
|
||||||
|
|
|
@ -18,6 +18,7 @@ from ereuse_devicehub.inventory.forms import (
|
||||||
DataWipeForm,
|
DataWipeForm,
|
||||||
FilterForm,
|
FilterForm,
|
||||||
LotDeviceForm,
|
LotDeviceForm,
|
||||||
|
LotDeviceShowForm,
|
||||||
LotForm,
|
LotForm,
|
||||||
NewActionForm,
|
NewActionForm,
|
||||||
NewDeviceForm,
|
NewDeviceForm,
|
||||||
|
@ -119,6 +120,7 @@ class DeviceListMix(GenericMixView):
|
||||||
'form_new_datawipe': form_new_datawipe,
|
'form_new_datawipe': form_new_datawipe,
|
||||||
'form_new_trade': form_new_trade,
|
'form_new_trade': form_new_trade,
|
||||||
'form_filter': form_filter,
|
'form_filter': form_filter,
|
||||||
|
'form_lot_device_del': LotDeviceShowForm(),
|
||||||
'lot': lot,
|
'lot': lot,
|
||||||
'tags': tags,
|
'tags': tags,
|
||||||
'list_devices': list_devices,
|
'list_devices': list_devices,
|
||||||
|
@ -173,6 +175,29 @@ class LotDeviceAddView(View):
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
|
||||||
|
class LotDeviceDeleteShowView(GenericMixView):
|
||||||
|
methods = ['POST']
|
||||||
|
decorators = [login_required]
|
||||||
|
template_name = 'inventory/removeDeviceslot2.html'
|
||||||
|
title = 'Remove from a lot'
|
||||||
|
|
||||||
|
def dispatch_request(self, lot_id=None):
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
|
next_url = request.referrer or url_for('inventory.devices.devicelist')
|
||||||
|
form = LotDeviceShowForm()
|
||||||
|
if not form.validate_on_submit():
|
||||||
|
messages.error('Error, you need select one or more devices!')
|
||||||
|
if lot_id:
|
||||||
|
next_url = url_for('inventory.devices.lotdevicelist', lot_id=form.id)
|
||||||
|
|
||||||
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
lots = self.get_lots()
|
||||||
|
form_lot = LotDeviceForm(devices=form.devices)
|
||||||
|
context = {'form': form_lot, 'title': self.title, 'lots': lots}
|
||||||
|
return flask.render_template(self.template_name, **context)
|
||||||
|
|
||||||
|
|
||||||
class LotDeviceDeleteView(View):
|
class LotDeviceDeleteView(View):
|
||||||
methods = ['POST']
|
methods = ['POST']
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
|
@ -676,6 +701,10 @@ devices.add_url_rule(
|
||||||
devices.add_url_rule(
|
devices.add_url_rule(
|
||||||
'/lot/devices/del/', view_func=LotDeviceDeleteView.as_view('lot_devices_del')
|
'/lot/devices/del/', view_func=LotDeviceDeleteView.as_view('lot_devices_del')
|
||||||
)
|
)
|
||||||
|
devices.add_url_rule(
|
||||||
|
'/lot/devices/del/show',
|
||||||
|
view_func=LotDeviceDeleteShowView.as_view('lot_devices_del_show'),
|
||||||
|
)
|
||||||
devices.add_url_rule('/lot/add/', view_func=LotCreateView.as_view('lot_add'))
|
devices.add_url_rule('/lot/add/', view_func=LotCreateView.as_view('lot_add'))
|
||||||
devices.add_url_rule(
|
devices.add_url_rule(
|
||||||
'/lot/<string:id>/del/', view_func=LotDeleteView.as_view('lot_del')
|
'/lot/<string:id>/del/', view_func=LotDeleteView.as_view('lot_del')
|
||||||
|
|
|
@ -92,6 +92,14 @@
|
||||||
Remove selected devices from a lot
|
Remove selected devices from a lot
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<form method="post" action="{{ url_for('inventory.devices.lot_devices_del_show') }}">
|
||||||
|
{% for f in form_lot_device_del %}
|
||||||
|
{{ f }}
|
||||||
|
{% endfor %}
|
||||||
|
<input type="submit" value="Remove selected devices from a lot" />
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-group dropdown ml-1" uib-dropdown="">
|
<div class="btn-group dropdown ml-1" uib-dropdown="">
|
||||||
|
|
Reference in New Issue