Allow retrieving all devices of a user

This commit is contained in:
Santiago L 2022-05-12 14:42:55 +02:00
parent 4ffbeec29d
commit 9e779d279c
2 changed files with 9 additions and 6 deletions

View File

@ -133,6 +133,7 @@ class FilterForm(FlaskForm):
super().__init__(*args, **kwargs)
self.lots = lots
self.lot_id = lot_id
self.unassigned = kwargs.pop('unassigned', False)
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.unassigned:
self.devices = self.devices.filter_by(lots=None)
def search(self):
self.filter_from_lots()

View File

@ -40,10 +40,10 @@ 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, unassigned=False):
super().get_context()
lots = self.context['lots']
form_filter = FilterForm(lots, lot_id)
form_filter = FilterForm(lots, lot_id, unassigned=unassigned)
devices = form_filter.search()
lot = None
@ -71,6 +71,7 @@ class DeviceListMix(GenericMixView):
'lot': lot,
'tags': self.get_user_tags(),
'list_devices': self.get_selected_devices(form_new_action),
'unassigned_devices': unassigned,
}
)
@ -93,7 +94,8 @@ class DeviceListMix(GenericMixView):
class DeviceListView(DeviceListMix):
def dispatch_request(self, lot_id=None):
self.get_context(lot_id)
unassigned = request.args.get('unassigned', False)
self.get_context(lot_id, unassigned)
return flask.render_template(self.template_name, **self.context)