diff --git a/dashboard/views.py b/dashboard/views.py index 0689271..9ea0840 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -98,7 +98,7 @@ class SearchView(InventaryMixin): if i: qry |= Q(value__startswith=i) - chids = Annotation.objects.filter( + chids = SystemProperty.objects.filter( type=Annotation.Type.SYSTEM, owner=self.request.user.institution ).filter( diff --git a/device/models.py b/device/models.py index 75d28db..15ec3b0 100644 --- a/device/models.py +++ b/device/models.py @@ -1,7 +1,7 @@ from django.db import models, connection from utils.constants import ALGOS -from evidence.models import SystemProperty, UserProperty, Property, Evidence +from evidence.models import SystemProperty, UserProperty, Property, Evidence from lot.models import DeviceLot @@ -159,8 +159,8 @@ class Device: ELSE 3 END, t1.created DESC - ) AS row_num - FROM evidence_annotation AS t1 + ) AS row_num + FROM evidence_systemproperty AS t1 LEFT JOIN lot_devicelot AS t2 ON t1.value = t2.device_id WHERE t2.device_id IS NULL AND t1.owner_id = {institution} @@ -181,12 +181,12 @@ class Device: sql += ";" - annotations = [] + properties = [] with connection.cursor() as cursor: cursor.execute(sql) - annotations = cursor.fetchall() + properties = cursor.fetchall() - devices = [cls(id=x[0]) for x in annotations] + devices = [cls(id=x[0]) for x in properties] count = cls.get_unassigned_count(institution) return devices, count @@ -194,7 +194,7 @@ class Device: def get_unassigned_count(cls, institution): sql = """ - WITH RankedAnnotations AS ( + WITH RankedProperties AS ( SELECT t1.value, t1.key, @@ -208,30 +208,30 @@ class Device: END, t1.created DESC ) AS row_num - FROM evidence_annotation AS t1 + FROM evidence_systemproperty AS t1 LEFT JOIN lot_devicelot AS t2 ON t1.value = t2.device_id WHERE t2.device_id IS NULL AND t1.owner_id = {institution} - AND t1.type = {type} + And t1.type = '{type}' ) SELECT COUNT(DISTINCT value) FROM - RankedAnnotations + RankedProperties WHERE row_num = 1 """.format( institution=institution.id, - type=Annotation.Type.SYSTEM, + type=Property.Type.SYSTEM, ) with connection.cursor() as cursor: cursor.execute(sql) return cursor.fetchall()[0][0] @classmethod - def get_annotation_from_uuid(cls, uuid, institution): + def get_properties_from_uuid(cls, uuid, institution): sql = """ - WITH RankedAnnotations AS ( + WITH RankedProperties AS ( SELECT t1.value, t1.key, @@ -245,29 +245,29 @@ class Device: END, t1.created DESC ) AS row_num - FROM evidence_annotation AS t1 + FROM evidence_systemproperty AS t1 LEFT JOIN lot_devicelot AS t2 ON t1.value = t2.device_id WHERE t2.device_id IS NULL AND t1.owner_id = {institution} - AND t1.type = {type} + AND t1.type = '{type}' AND t1.uuid = '{uuid}' ) SELECT DISTINCT value FROM - RankedAnnotations + RankedProperties WHERE row_num = 1; """.format( uuid=uuid.replace("-", ""), institution=institution.id, - type=Annotation.Type.SYSTEM, + type=Property.Type.SYSTEM, ) - annotations = [] + properties = [] with connection.cursor() as cursor: cursor.execute(sql) - annotations = cursor.fetchall() + properties = cursor.fetchall() return cls(id=annotations[0][0]) diff --git a/evidence/models.py b/evidence/models.py index 51c7e81..78166fb 100644 --- a/evidence/models.py +++ b/evidence/models.py @@ -216,7 +216,7 @@ class Evidence: def get_all(cls, user): return SystemProperty.objects.filter( owner=user.institution, - type=SystemProperty.Type.SYSTEM, + type=Property.Type.SYSTEM, key="hidalgo1", ).order_by("-created").values_list("uuid", "created").distinct() diff --git a/evidence/views.py b/evidence/views.py index ddec292..348a15b 100644 --- a/evidence/views.py +++ b/evidence/views.py @@ -13,7 +13,7 @@ from django.views.generic.edit import ( ) from dashboard.mixins import DashboardView, Http403 -from evidence.models import Property, SystemProperty, UserProperty +from evidence.models import Property, SystemProperty, UserProperty, Evidence from evidence.forms import ( UploadForm, UserTagForm, diff --git a/utils/device.py b/utils/device.py index 6f246c8..43d8e1b 100644 --- a/utils/device.py +++ b/utils/device.py @@ -76,7 +76,7 @@ def create_property(doc, user, commit=False): 'uuid': doc['uuid'], 'owner': user.institution, 'user': user, - 'type': Annotation.Type.SYSTEM, + 'type': Property.Type.SYSTEM, 'key': 'CUSTOMER_ID', 'value': doc['CUSTOMER_ID'], }