2024-07-01 10:19:21 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2024-07-10 11:55:57 +00:00
|
|
|
from dashboard.mixins import InventaryMixin, DetailsMixin
|
2024-07-05 13:32:07 +00:00
|
|
|
from device.models import Device
|
2024-07-30 11:37:08 +00:00
|
|
|
from lot.models import Lot
|
2024-07-01 10:19:21 +00:00
|
|
|
|
|
|
|
|
2024-07-09 11:34:30 +00:00
|
|
|
class UnassignedDevicesView(InventaryMixin):
|
2024-07-05 13:32:07 +00:00
|
|
|
template_name = "unassigned_devices.html"
|
|
|
|
section = "Unassigned"
|
|
|
|
title = _("Unassigned Devices")
|
|
|
|
breadcrumb = "Devices / Unassigned Devices"
|
2024-07-01 10:19:21 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
2024-07-19 15:40:01 +00:00
|
|
|
devices = Device.get_unassigned(self.request.user)
|
2024-07-15 14:23:14 +00:00
|
|
|
|
2024-07-10 11:55:57 +00:00
|
|
|
context.update({
|
2024-07-18 15:21:22 +00:00
|
|
|
'devices': devices,
|
2024-07-10 11:55:57 +00:00
|
|
|
})
|
2024-07-18 15:21:22 +00:00
|
|
|
|
2024-07-10 11:55:57 +00:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class LotDashboardView(InventaryMixin, DetailsMixin):
|
|
|
|
template_name = "unassigned_devices.html"
|
2024-07-19 15:40:01 +00:00
|
|
|
section = "dashboard_lot"
|
2024-07-10 11:55:57 +00:00
|
|
|
title = _("Lot Devices")
|
2024-07-19 15:40:01 +00:00
|
|
|
breadcrumb = "Lot / Devices"
|
2024-07-10 11:55:57 +00:00
|
|
|
model = Lot
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
2024-07-19 15:40:01 +00:00
|
|
|
devices = self.get_devices()
|
2024-07-30 17:38:04 +00:00
|
|
|
lot = context.get('object')
|
2024-07-01 10:19:21 +00:00
|
|
|
context.update({
|
2024-07-05 13:32:07 +00:00
|
|
|
'devices': devices,
|
2024-07-30 17:38:04 +00:00
|
|
|
'lot': lot,
|
2024-07-01 10:19:21 +00:00
|
|
|
})
|
|
|
|
return context
|
2024-07-19 15:40:01 +00:00
|
|
|
|
|
|
|
def get_devices(self):
|
|
|
|
chids = self.object.devicelot_set.all().values_list("device_id", flat=True).distinct()
|
|
|
|
return [Device(id=x) for x in chids]
|