refactorice
This commit is contained in:
parent
d4e6469ddf
commit
252c5285d8
|
@ -52,7 +52,7 @@ from ereuse_devicehub.resources.user.exceptions import InsufficientPermission
|
||||||
from ereuse_devicehub.resources.user.models import User
|
from ereuse_devicehub.resources.user.models import User
|
||||||
|
|
||||||
DEVICES = {
|
DEVICES = {
|
||||||
"All": ["All"],
|
"All": ["Devices", "Components"],
|
||||||
"Computer": [
|
"Computer": [
|
||||||
"Desktop",
|
"Desktop",
|
||||||
"Laptop",
|
"Laptop",
|
||||||
|
|
|
@ -40,32 +40,13 @@ logger = logging.getLogger(__name__)
|
||||||
class DeviceListMix(GenericMixView):
|
class DeviceListMix(GenericMixView):
|
||||||
template_name = 'inventory/device_list.html'
|
template_name = 'inventory/device_list.html'
|
||||||
|
|
||||||
def get_context(self, lot_id):
|
def _get_devices(self, lots, lot):
|
||||||
super().get_context()
|
|
||||||
lots = self.context['lots']
|
|
||||||
form_filter = FilterForm()
|
|
||||||
filter_types = 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:
|
if lot_id:
|
||||||
lot = lots.filter(Lot.id == lot_id).one()
|
lot = lots.filter(Lot.id == lot_id).one()
|
||||||
devices = lot.devices
|
devices = lot.devices
|
||||||
if "All" not in filter_types:
|
if "All" not in filter_types:
|
||||||
devices = [dev for dev in lot.devices if dev.type in filter_types]
|
devices = [dev for dev in lot.devices if dev.type in filter_types]
|
||||||
devices = sorted(devices, key=lambda x: x.updated, reverse=True)
|
devices = sorted(devices, key=lambda x: x.updated, reverse=True)
|
||||||
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:
|
else:
|
||||||
if "All" in filter_types:
|
if "All" in filter_types:
|
||||||
devices = (
|
devices = (
|
||||||
|
@ -81,6 +62,31 @@ class DeviceListMix(GenericMixView):
|
||||||
.order_by(Device.updated.desc())
|
.order_by(Device.updated.desc())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return devices
|
||||||
|
|
||||||
|
def get_context(self, lot_id):
|
||||||
|
super().get_context()
|
||||||
|
lots = self.context['lots']
|
||||||
|
form_filter = FilterForm()
|
||||||
|
filter_types = 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_action = NewActionForm()
|
||||||
form_new_allocate = AllocateForm()
|
form_new_allocate = AllocateForm()
|
||||||
form_new_datawipe = DataWipeForm()
|
form_new_datawipe = DataWipeForm()
|
||||||
|
@ -92,7 +98,7 @@ class DeviceListMix(GenericMixView):
|
||||||
|
|
||||||
self.context.update(
|
self.context.update(
|
||||||
{
|
{
|
||||||
'devices': devices,
|
'devices': self._get_devices(lots, lot),
|
||||||
'form_tag_device': TagDeviceForm(),
|
'form_tag_device': TagDeviceForm(),
|
||||||
'form_new_action': form_new_action,
|
'form_new_action': form_new_action,
|
||||||
'form_new_allocate': form_new_allocate,
|
'form_new_allocate': form_new_allocate,
|
||||||
|
|
Reference in New Issue