Merge pull request #271 from eReuse/feature/all-device-list
Feature: 3196 all device list
This commit is contained in:
commit
a444579c05
|
@ -133,6 +133,7 @@ class FilterForm(FlaskForm):
|
|||
super().__init__(*args, **kwargs)
|
||||
self.lots = lots
|
||||
self.lot_id = lot_id
|
||||
self.only_unassigned = kwargs.pop('only_unassigned', True)
|
||||
self._get_types()
|
||||
|
||||
def _get_types(self):
|
||||
|
@ -148,9 +149,9 @@ class FilterForm(FlaskForm):
|
|||
device_ids = (d.id for d in self.lot.devices)
|
||||
self.devices = Device.query.filter(Device.id.in_(device_ids))
|
||||
else:
|
||||
self.devices = Device.query.filter(Device.owner_id == g.user.id).filter_by(
|
||||
lots=None
|
||||
)
|
||||
self.devices = Device.query.filter(Device.owner_id == g.user.id)
|
||||
if self.only_unassigned:
|
||||
self.devices = self.devices.filter_by(lots=None)
|
||||
|
||||
def search(self):
|
||||
self.filter_from_lots()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import csv
|
||||
import logging
|
||||
from distutils.util import strtobool
|
||||
from io import StringIO
|
||||
|
||||
import flask
|
||||
|
@ -40,60 +41,64 @@ logger = logging.getLogger(__name__)
|
|||
class DeviceListMix(GenericMixView):
|
||||
template_name = 'inventory/device_list.html'
|
||||
|
||||
def get_context(self, lot_id):
|
||||
def get_context(self, lot_id, only_unassigned=True):
|
||||
super().get_context()
|
||||
lots = self.context['lots']
|
||||
form_filter = FilterForm(lots, lot_id)
|
||||
form_filter = FilterForm(lots, lot_id, only_unassigned=only_unassigned)
|
||||
devices = form_filter.search()
|
||||
lot = None
|
||||
tags = (
|
||||
Tag.query.filter(Tag.owner_id == current_user.id)
|
||||
.filter(Tag.device_id.is_(None))
|
||||
.order_by(Tag.id.asc())
|
||||
)
|
||||
|
||||
if lot_id:
|
||||
lot = lots.filter(Lot.id == lot_id).one()
|
||||
form_new_action = NewActionForm(lot=lot.id)
|
||||
form_new_allocate = AllocateForm(lot=lot.id)
|
||||
form_new_datawipe = DataWipeForm(lot=lot.id)
|
||||
form_new_trade = TradeForm(
|
||||
lot=lot.id,
|
||||
user_to=g.user.email,
|
||||
user_from=g.user.email,
|
||||
)
|
||||
else:
|
||||
form_new_action = NewActionForm()
|
||||
form_new_allocate = AllocateForm()
|
||||
form_new_datawipe = DataWipeForm()
|
||||
form_new_trade = ''
|
||||
action_devices = form_new_action.devices.data
|
||||
list_devices = []
|
||||
if action_devices:
|
||||
list_devices.extend([int(x) for x in action_devices.split(",")])
|
||||
|
||||
form_new_action = NewActionForm(lot=lot_id)
|
||||
self.context.update(
|
||||
{
|
||||
'devices': devices,
|
||||
'form_tag_device': TagDeviceForm(),
|
||||
'form_new_action': form_new_action,
|
||||
'form_new_allocate': form_new_allocate,
|
||||
'form_new_datawipe': form_new_datawipe,
|
||||
'form_new_allocate': AllocateForm(lot=lot_id),
|
||||
'form_new_datawipe': DataWipeForm(lot=lot_id),
|
||||
'form_new_trade': form_new_trade,
|
||||
'form_filter': form_filter,
|
||||
'form_print_labels': PrintLabelsForm(),
|
||||
'lot': lot,
|
||||
'tags': tags,
|
||||
'list_devices': list_devices,
|
||||
'tags': self.get_user_tags(),
|
||||
'list_devices': self.get_selected_devices(form_new_action),
|
||||
'unassigned_devices': only_unassigned,
|
||||
}
|
||||
)
|
||||
|
||||
return self.context
|
||||
|
||||
def get_user_tags(self):
|
||||
return (
|
||||
Tag.query.filter(Tag.owner_id == current_user.id)
|
||||
.filter(Tag.device_id.is_(None))
|
||||
.order_by(Tag.id.asc())
|
||||
)
|
||||
|
||||
def get_selected_devices(self, action_form):
|
||||
"""Retrieve selected devices (when action form is submited)"""
|
||||
action_devices = action_form.devices.data
|
||||
if action_devices:
|
||||
return [int(x) for x in action_devices.split(",")]
|
||||
return []
|
||||
|
||||
|
||||
class DeviceListView(DeviceListMix):
|
||||
def dispatch_request(self, lot_id=None):
|
||||
self.get_context(lot_id)
|
||||
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)
|
||||
|
||||
|
||||
|
|
|
@ -101,6 +101,15 @@
|
|||
</a>
|
||||
</li><!-- End Dashboard Nav -->
|
||||
|
||||
<li class="nav-heading">Devices</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<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') }}">
|
||||
<i class="bi-menu-button-wide"></i>
|
||||
|
|
|
@ -7,7 +7,11 @@
|
|||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="{{ url_for('inventory.devicelist')}}">Inventory</a></li>
|
||||
{% if not lot %}
|
||||
{% if unassigned_devices %}
|
||||
<li class="breadcrumb-item active">Unassigned</li>
|
||||
{% else %}
|
||||
<li class="breadcrumb-item active">All devices</li>
|
||||
{% endif %}
|
||||
{% elif lot.is_temporary %}
|
||||
<li class="breadcrumb-item active">Temporary Lot</li>
|
||||
<li class="breadcrumb-item active">{{ lot.name }}</li>
|
||||
|
|
Reference in New Issue