diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index fffefa39..cec788b4 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -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): diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index e11e9d2c..09e61535 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -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) diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html index 2f254204..74147824 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html @@ -104,14 +104,14 @@