2024-07-15 14:23:14 +00:00
|
|
|
import json
|
|
|
|
|
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 django.db.models import Count
|
|
|
|
from dashboard.mixins import InventaryMixin, DetailsMixin
|
2024-07-05 13:32:07 +00:00
|
|
|
from device.models import Device
|
2024-07-15 14:23:14 +00:00
|
|
|
from snapshot.xapian import search
|
|
|
|
from snapshot.models import Annotation
|
2024-07-10 11:55:57 +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-15 14:23:14 +00:00
|
|
|
annotations = Annotation.objects.filter(
|
|
|
|
owner=self.request.user).filter(
|
|
|
|
key="hidalgo1").order_by('created')
|
|
|
|
# 'created').distinct('value')
|
|
|
|
# ).annotate(num_lots=Count('lot')).filter(num_lots=0)
|
|
|
|
|
|
|
|
hids = {}
|
|
|
|
ids = []
|
|
|
|
for x in annotations:
|
|
|
|
if not hids.get(x.key):
|
|
|
|
hids[x.key] = x.uuid
|
|
|
|
ids.append(str(x.uuid))
|
|
|
|
|
|
|
|
devices = []
|
|
|
|
for xa in search(ids):
|
|
|
|
# import pdb; pdb.set_trace()
|
|
|
|
snap = json.loads(xa.document.get_data())
|
|
|
|
dev = snap.get("device", {})
|
|
|
|
dev["id"] = snap["uuid"]
|
|
|
|
devices.append(dev)
|
|
|
|
|
2024-07-10 11:55:57 +00:00
|
|
|
context.update({
|
2024-07-15 14:23:14 +00:00
|
|
|
'devices': devices
|
2024-07-10 11:55:57 +00:00
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
2024-07-10 14:15:37 +00:00
|
|
|
class AllDevicesView(InventaryMixin):
|
|
|
|
template_name = "unassigned_devices.html"
|
|
|
|
section = "All"
|
|
|
|
title = _("All Devices")
|
|
|
|
breadcrumb = "Devices / All Devices"
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
devices = Device.objects.filter(owner=self.request.user)
|
|
|
|
context.update({
|
|
|
|
'devices': devices,
|
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
2024-07-10 11:55:57 +00:00
|
|
|
class LotDashboardView(InventaryMixin, DetailsMixin):
|
|
|
|
template_name = "unassigned_devices.html"
|
|
|
|
section = "Unassigned"
|
|
|
|
title = _("Lot Devices")
|
|
|
|
breadcrumb = "Devices / Lot Devices"
|
|
|
|
model = Lot
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
devices = self.object.devices.filter(owner=self.request.user)
|
2024-07-01 10:19:21 +00:00
|
|
|
context.update({
|
2024-07-05 13:32:07 +00:00
|
|
|
'devices': devices,
|
2024-07-01 10:19:21 +00:00
|
|
|
})
|
|
|
|
return context
|