devicehub-django/dashboard/views.py

38 lines
1.2 KiB
Python
Raw Normal View History

2024-07-01 10:19:21 +00:00
from django.utils.translation import gettext_lazy as _
from django.shortcuts import Http404
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_devices(self, user, offset, limit):
return Device.get_unassigned(self.request.user, offset, limit)
2024-07-10 11:55:57 +00:00
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-30 17:38:04 +00:00
lot = context.get('object')
2024-07-01 10:19:21 +00:00
context.update({
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, user, offset, limit):
2024-07-19 15:40:01 +00:00
chids = self.object.devicelot_set.all().values_list("device_id", flat=True).distinct()
2024-10-02 10:27:20 +00:00
chids_page = chids[offset:offset+limit]
return [Device(id=x) for x in chids_page], chids.count()