filter search in lists
This commit is contained in:
parent
95a8b13a6b
commit
598b91e22b
|
@ -35,6 +35,26 @@ from ereuse_devicehub.resources.action.models import Trade
|
||||||
from sqlalchemy import or_
|
from sqlalchemy import or_
|
||||||
|
|
||||||
|
|
||||||
|
DEVICES = [
|
||||||
|
("Computer", "Computer"),
|
||||||
|
("Monitor", "Monitor"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class FilterForm(FlaskForm):
|
||||||
|
filter = SelectField('', choices=DEVICES, default="Comupter",
|
||||||
|
render_kw={'class': "form-select"})
|
||||||
|
|
||||||
|
def search(self):
|
||||||
|
|
||||||
|
type_device = {
|
||||||
|
None: ['Desktop', 'Laptop', 'Server'],
|
||||||
|
'Computer': ['Computer'],
|
||||||
|
'Monitor': ['Monitor'],
|
||||||
|
}
|
||||||
|
return type_device.get(request.args.get('filter')) or type_device[None]
|
||||||
|
|
||||||
|
|
||||||
class LotDeviceForm(FlaskForm):
|
class LotDeviceForm(FlaskForm):
|
||||||
lot = StringField('Lot', [validators.UUID()])
|
lot = StringField('Lot', [validators.UUID()])
|
||||||
devices = StringField('Devices', [validators.length(min=1)])
|
devices = StringField('Devices', [validators.length(min=1)])
|
||||||
|
|
|
@ -13,6 +13,7 @@ from ereuse_devicehub import messages
|
||||||
from ereuse_devicehub.inventory.forms import (
|
from ereuse_devicehub.inventory.forms import (
|
||||||
AllocateForm,
|
AllocateForm,
|
||||||
DataWipeForm,
|
DataWipeForm,
|
||||||
|
FilterForm,
|
||||||
LotDeviceForm,
|
LotDeviceForm,
|
||||||
LotForm,
|
LotForm,
|
||||||
NewActionForm,
|
NewActionForm,
|
||||||
|
@ -40,15 +41,9 @@ class DeviceListMix(View):
|
||||||
template_name = 'inventory/device_list.html'
|
template_name = 'inventory/device_list.html'
|
||||||
|
|
||||||
def get_context(self, lot_id):
|
def get_context(self, lot_id):
|
||||||
# TODO @cayop adding filter
|
form_filter = FilterForm()
|
||||||
# https://github.com/eReuse/devicehub-teal/blob/testing/ereuse_devicehub/resources/device/views.py#L56
|
filter_types = form_filter.search()
|
||||||
import pdb; pdb.set_trace()
|
|
||||||
type_device = {
|
|
||||||
None: ['Desktop', 'Laptop', 'Server'],
|
|
||||||
'Computer': ['Computer'],
|
|
||||||
'Monitor': ['Monitor'],
|
|
||||||
}
|
|
||||||
filter_types = type_device[request.get('filter')]
|
|
||||||
lots = Lot.query.outerjoin(Trade) \
|
lots = Lot.query.outerjoin(Trade) \
|
||||||
.filter(or_(Trade.user_from == g.user,
|
.filter(or_(Trade.user_from == g.user,
|
||||||
Trade.user_to == g.user,
|
Trade.user_to == g.user,
|
||||||
|
@ -61,7 +56,6 @@ class DeviceListMix(View):
|
||||||
)
|
)
|
||||||
|
|
||||||
if lot_id:
|
if lot_id:
|
||||||
# import pdb; pdb.set_trace()
|
|
||||||
lot = lots.filter(Lot.id == lot_id).one()
|
lot = lots.filter(Lot.id == lot_id).one()
|
||||||
devices = [dev for dev in lot.devices if dev.type in filter_types]
|
devices = [dev for dev in lot.devices if dev.type in filter_types]
|
||||||
devices = sorted(devices, key=lambda x: x.updated, reverse=True)
|
devices = sorted(devices, key=lambda x: x.updated, reverse=True)
|
||||||
|
@ -98,6 +92,7 @@ class DeviceListMix(View):
|
||||||
'form_new_allocate': form_new_allocate,
|
'form_new_allocate': form_new_allocate,
|
||||||
'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,
|
||||||
'lot': lot,
|
'lot': lot,
|
||||||
'tags': tags,
|
'tags': tags,
|
||||||
'list_devices': list_devices,
|
'list_devices': list_devices,
|
||||||
|
|
|
@ -280,11 +280,17 @@
|
||||||
|
|
||||||
<h5 class="card-title">Computers</h5>
|
<h5 class="card-title">Computers</h5>
|
||||||
<form method="get">
|
<form method="get">
|
||||||
<select class="form-data" name="filter">
|
<div class="row">
|
||||||
<option value="Computer">Computer</option>
|
<div class="col-2">
|
||||||
<option value="Monitor">Monitor</option>
|
{% for f in form_filter %}
|
||||||
</select>
|
{{ f }}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div class="col-1">
|
||||||
<input type="submit" class="btn btn-primary" value="Search" />
|
<input type="submit" class="btn btn-primary" value="Search" />
|
||||||
|
</div>
|
||||||
|
<div class="col"></div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
Reference in a new issue