Keep unassigned as default option on device list
Unassigned devices are the ones that require user attention and also all devices view will generate larger responses and more server load.
This commit is contained in:
parent
4406c78aed
commit
d54f2166dc
|
@ -133,7 +133,7 @@ class FilterForm(FlaskForm):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.lots = lots
|
self.lots = lots
|
||||||
self.lot_id = lot_id
|
self.lot_id = lot_id
|
||||||
self.unassigned = kwargs.pop('unassigned', False)
|
self.only_unassigned = kwargs.pop('only_unassigned', True)
|
||||||
self._get_types()
|
self._get_types()
|
||||||
|
|
||||||
def _get_types(self):
|
def _get_types(self):
|
||||||
|
@ -150,7 +150,7 @@ class FilterForm(FlaskForm):
|
||||||
self.devices = Device.query.filter(Device.id.in_(device_ids))
|
self.devices = Device.query.filter(Device.id.in_(device_ids))
|
||||||
else:
|
else:
|
||||||
self.devices = Device.query.filter(Device.owner_id == g.user.id)
|
self.devices = Device.query.filter(Device.owner_id == g.user.id)
|
||||||
if self.unassigned:
|
if self.only_unassigned:
|
||||||
self.devices = self.devices.filter_by(lots=None)
|
self.devices = self.devices.filter_by(lots=None)
|
||||||
|
|
||||||
def search(self):
|
def search(self):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import csv
|
import csv
|
||||||
import logging
|
import logging
|
||||||
|
from distutils.util import strtobool
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
@ -40,10 +41,10 @@ logger = logging.getLogger(__name__)
|
||||||
class DeviceListMix(GenericMixView):
|
class DeviceListMix(GenericMixView):
|
||||||
template_name = 'inventory/device_list.html'
|
template_name = 'inventory/device_list.html'
|
||||||
|
|
||||||
def get_context(self, lot_id, unassigned=False):
|
def get_context(self, lot_id, only_unassigned=True):
|
||||||
super().get_context()
|
super().get_context()
|
||||||
lots = self.context['lots']
|
lots = self.context['lots']
|
||||||
form_filter = FilterForm(lots, lot_id, unassigned=unassigned)
|
form_filter = FilterForm(lots, lot_id, only_unassigned=only_unassigned)
|
||||||
devices = form_filter.search()
|
devices = form_filter.search()
|
||||||
lot = None
|
lot = None
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ class DeviceListMix(GenericMixView):
|
||||||
'lot': lot,
|
'lot': lot,
|
||||||
'tags': self.get_user_tags(),
|
'tags': self.get_user_tags(),
|
||||||
'list_devices': self.get_selected_devices(form_new_action),
|
'list_devices': self.get_selected_devices(form_new_action),
|
||||||
'unassigned_devices': unassigned,
|
'unassigned_devices': only_unassigned,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -94,8 +95,10 @@ class DeviceListMix(GenericMixView):
|
||||||
|
|
||||||
class DeviceListView(DeviceListMix):
|
class DeviceListView(DeviceListMix):
|
||||||
def dispatch_request(self, lot_id=None):
|
def dispatch_request(self, lot_id=None):
|
||||||
unassigned = request.args.get('unassigned', False)
|
only_unassigned = request.args.get(
|
||||||
self.get_context(lot_id, unassigned)
|
'only_unassigned', default=True, type=strtobool
|
||||||
|
)
|
||||||
|
self.get_context(lot_id, only_unassigned)
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -104,14 +104,14 @@
|
||||||
<li class="nav-heading">Devices</li>
|
<li class="nav-heading">Devices</li>
|
||||||
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link collapsed" href="{{ url_for('inventory.devicelist') }}">
|
<a class="nav-link collapsed" href="{{ url_for('inventory.devicelist') }}?only_unassigned=false">
|
||||||
<i class="bi bi-laptop"></i>
|
<i class="bi bi-laptop"></i>
|
||||||
<span>All devices</span>
|
<span>All devices</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link collapsed" href="{{ url_for('inventory.devicelist') }}?unassigned=true">
|
<a class="nav-link collapsed" href="{{ url_for('inventory.devicelist') }}">
|
||||||
<i class="bi-menu-button-wide"></i>
|
<i class="bi-menu-button-wide"></i>
|
||||||
<span>Unassigned devices</span>
|
<span>Unassigned devices</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
Reference in New Issue