Merge pull request #336 from eReuse/bugfix/3728-filter-unassigned
change only_unassigned for one specific url
This commit is contained in:
commit
560c9004ef
|
@ -125,10 +125,10 @@ class FilterForm(FlaskForm):
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, lots, lot_id, *args, **kwargs):
|
def __init__(self, lots, lot_id, *args, **kwargs):
|
||||||
|
self.all_devices = kwargs.pop('all_devices', False)
|
||||||
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.only_unassigned = kwargs.pop('only_unassigned', True)
|
|
||||||
self._get_types()
|
self._get_types()
|
||||||
|
|
||||||
def _get_types(self):
|
def _get_types(self):
|
||||||
|
@ -149,7 +149,7 @@ class FilterForm(FlaskForm):
|
||||||
self.devices = Device.query.filter(Device.owner_id == g.user.id).filter(
|
self.devices = Device.query.filter(Device.owner_id == g.user.id).filter(
|
||||||
Device.binding == None # noqa: E711
|
Device.binding == None # noqa: E711
|
||||||
)
|
)
|
||||||
if self.only_unassigned:
|
if not self.all_devices:
|
||||||
self.devices = self.devices.filter_by(lots=None)
|
self.devices = self.devices.filter_by(lots=None)
|
||||||
|
|
||||||
def search(self):
|
def search(self):
|
||||||
|
|
|
@ -2,7 +2,6 @@ import copy
|
||||||
import csv
|
import csv
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from distutils.util import strtobool
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -59,10 +58,11 @@ logger = logging.getLogger(__name__)
|
||||||
class DeviceListMixin(GenericMixin):
|
class DeviceListMixin(GenericMixin):
|
||||||
template_name = 'inventory/device_list.html'
|
template_name = 'inventory/device_list.html'
|
||||||
|
|
||||||
def get_context(self, lot_id, only_unassigned=True):
|
def get_context(self, lot_id=None, all_devices=False):
|
||||||
super().get_context()
|
super().get_context()
|
||||||
|
|
||||||
lots = self.context['lots']
|
lots = self.context['lots']
|
||||||
form_filter = FilterForm(lots, lot_id, only_unassigned=only_unassigned)
|
form_filter = FilterForm(lots, lot_id, all_devices=all_devices)
|
||||||
devices = form_filter.search()
|
devices = form_filter.search()
|
||||||
lot = None
|
lot = None
|
||||||
form_transfer = ''
|
form_transfer = ''
|
||||||
|
@ -91,7 +91,7 @@ class DeviceListMixin(GenericMixin):
|
||||||
'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': only_unassigned,
|
'all_devices': all_devices,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -114,10 +114,13 @@ class DeviceListMixin(GenericMixin):
|
||||||
|
|
||||||
class DeviceListView(DeviceListMixin):
|
class DeviceListView(DeviceListMixin):
|
||||||
def dispatch_request(self, lot_id=None):
|
def dispatch_request(self, lot_id=None):
|
||||||
only_unassigned = request.args.get(
|
self.get_context(lot_id)
|
||||||
'only_unassigned', default=True, type=strtobool
|
return flask.render_template(self.template_name, **self.context)
|
||||||
)
|
|
||||||
self.get_context(lot_id, only_unassigned)
|
|
||||||
|
class AllDeviceListView(DeviceListMixin):
|
||||||
|
def dispatch_request(self):
|
||||||
|
self.get_context(all_devices=True)
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,7 +131,7 @@ class AdvancedSearchView(DeviceListMixin):
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
query = request.args.get('q', '')
|
query = request.args.get('q', '')
|
||||||
self.get_context(None)
|
self.get_context()
|
||||||
form = AdvancedSearchForm(q=query)
|
form = AdvancedSearchForm(q=query)
|
||||||
self.context.update({'devices': form.devices, 'advanced_form': form})
|
self.context.update({'devices': form.devices, 'advanced_form': form})
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
@ -1202,6 +1205,9 @@ devices.add_url_rule(
|
||||||
view_func=NewTradeDocumentView.as_view('trade_document_add'),
|
view_func=NewTradeDocumentView.as_view('trade_document_add'),
|
||||||
)
|
)
|
||||||
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
|
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
|
||||||
|
devices.add_url_rule(
|
||||||
|
'/all/device/', view_func=AllDeviceListView.as_view('alldevicelist')
|
||||||
|
)
|
||||||
devices.add_url_rule(
|
devices.add_url_rule(
|
||||||
'/search/', view_func=AdvancedSearchView.as_view('advanced_search')
|
'/search/', view_func=AdvancedSearchView.as_view('advanced_search')
|
||||||
)
|
)
|
||||||
|
|
|
@ -160,7 +160,7 @@
|
||||||
<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') }}?only_unassigned=false">
|
<a class="nav-link collapsed" href="{{ url_for('inventory.alldevicelist') }}">
|
||||||
<i class="bi bi-laptop"></i>
|
<i class="bi bi-laptop"></i>
|
||||||
<span>All devices</span>
|
<span>All devices</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li class="breadcrumb-item"><a href="{{ url_for('inventory.devicelist')}}">Inventory</a></li>
|
<li class="breadcrumb-item"><a href="{{ url_for('inventory.devicelist')}}">Inventory</a></li>
|
||||||
{% if not lot %}
|
{% if not lot %}
|
||||||
{% if unassigned_devices %}
|
{% if all_devices %}
|
||||||
<li class="breadcrumb-item active">Unassigned</li>
|
|
||||||
{% else %}
|
|
||||||
<li class="breadcrumb-item active">All devices</li>
|
<li class="breadcrumb-item active">All devices</li>
|
||||||
|
{% else %}
|
||||||
|
<li class="breadcrumb-item active">Unassigned</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elif lot.is_temporary %}
|
{% elif lot.is_temporary %}
|
||||||
<li class="breadcrumb-item active">Temporary Lot</li>
|
<li class="breadcrumb-item active">Temporary Lot</li>
|
||||||
|
@ -247,7 +247,7 @@
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
{% if unassigned_devices %}
|
{% if not all_devices %}
|
||||||
<span class="dropdown-item" style="color: #999ea4;">
|
<span class="dropdown-item" style="color: #999ea4;">
|
||||||
<i class="bi bi-file-spreadsheet"></i>
|
<i class="bi bi-file-spreadsheet"></i>
|
||||||
Devices Lots Spreadsheet
|
Devices Lots Spreadsheet
|
||||||
|
|
|
@ -55,6 +55,7 @@ def test_api_docs(client: Client):
|
||||||
'/inventory/device/add/',
|
'/inventory/device/add/',
|
||||||
'/inventory/device/{id}/',
|
'/inventory/device/{id}/',
|
||||||
'/inventory/device/{dhid}/binding/',
|
'/inventory/device/{dhid}/binding/',
|
||||||
|
'/inventory/all/device/',
|
||||||
'/inventory/export/{export_id}/',
|
'/inventory/export/{export_id}/',
|
||||||
'/inventory/lot/add/',
|
'/inventory/lot/add/',
|
||||||
'/inventory/lot/{id}/',
|
'/inventory/lot/{id}/',
|
||||||
|
|
Reference in New Issue