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)
|
||||
self.lots = lots
|
||||
self.lot_id = lot_id
|
||||
self.unassigned = kwargs.pop('unassigned', False)
|
||||
self.only_unassigned = kwargs.pop('only_unassigned', True)
|
||||
self._get_types()
|
||||
|
||||
def _get_types(self):
|
||||
|
@ -150,7 +150,7 @@ class FilterForm(FlaskForm):
|
|||
self.devices = Device.query.filter(Device.id.in_(device_ids))
|
||||
else:
|
||||
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)
|
||||
|
||||
def search(self):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import csv
|
||||
import logging
|
||||
from distutils.util import strtobool
|
||||
from io import StringIO
|
||||
|
||||
import flask
|
||||
|
@ -40,10 +41,10 @@ logger = logging.getLogger(__name__)
|
|||
class DeviceListMix(GenericMixView):
|
||||
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()
|
||||
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()
|
||||
lot = None
|
||||
|
||||
|
@ -71,7 +72,7 @@ class DeviceListMix(GenericMixView):
|
|||
'lot': lot,
|
||||
'tags': self.get_user_tags(),
|
||||
'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):
|
||||
def dispatch_request(self, lot_id=None):
|
||||
unassigned = request.args.get('unassigned', False)
|
||||
self.get_context(lot_id, unassigned)
|
||||
only_unassigned = request.args.get(
|
||||
'only_unassigned', default=True, type=strtobool
|
||||
)
|
||||
self.get_context(lot_id, only_unassigned)
|
||||
return flask.render_template(self.template_name, **self.context)
|
||||
|
||||
|
||||
|
|
|
@ -104,14 +104,14 @@
|
|||
<li class="nav-heading">Devices</li>
|
||||
|
||||
<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>
|
||||
<span>All devices</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<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>
|
||||
<span>Unassigned devices</span>
|
||||
</a>
|
||||
|
|
Reference in New Issue