renaming annotation to variable
This commit is contained in:
parent
296fab8cf6
commit
4c69906f24
|
@ -86,7 +86,7 @@ class SearchView(InventaryMixin):
|
||||||
def get_properties(self, xp):
|
def get_properties(self, xp):
|
||||||
snap = xp.document.get_data()
|
snap = xp.document.get_data()
|
||||||
uuid = json.loads(snap).get('uuid')
|
uuid = json.loads(snap).get('uuid')
|
||||||
return Device.get_annotation_from_uuid(uuid, self.request.user.institution)
|
return Device.get_properties_from_uuid(uuid, self.request.user.institution)
|
||||||
|
|
||||||
def search_hids(self, query, offset, limit):
|
def search_hids(self, query, offset, limit):
|
||||||
qry = Q()
|
qry = Q()
|
||||||
|
@ -95,7 +95,7 @@ class SearchView(InventaryMixin):
|
||||||
if i:
|
if i:
|
||||||
qry |= Q(value__startswith=i)
|
qry |= Q(value__startswith=i)
|
||||||
|
|
||||||
chids = Annotation.objects.filter(
|
chids = SystemProperty.objects.filter(
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Annotation.Type.SYSTEM,
|
||||||
owner=self.request.user.institution
|
owner=self.request.user.institution
|
||||||
).filter(
|
).filter(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.db import models, connection
|
from django.db import models, connection
|
||||||
|
|
||||||
from utils.constants import ALGOS
|
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
|
from lot.models import DeviceLot
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ class Device:
|
||||||
END,
|
END,
|
||||||
t1.created DESC
|
t1.created DESC
|
||||||
) AS row_num
|
) 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
|
LEFT JOIN lot_devicelot AS t2 ON t1.value = t2.device_id
|
||||||
WHERE t2.device_id IS NULL
|
WHERE t2.device_id IS NULL
|
||||||
AND t1.owner_id = {institution}
|
AND t1.owner_id = {institution}
|
||||||
|
@ -170,12 +170,12 @@ class Device:
|
||||||
|
|
||||||
sql += ";"
|
sql += ";"
|
||||||
|
|
||||||
annotations = []
|
properties = []
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
cursor.execute(sql)
|
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)
|
count = cls.get_unassigned_count(institution)
|
||||||
return devices, count
|
return devices, count
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ class Device:
|
||||||
def get_unassigned_count(cls, institution):
|
def get_unassigned_count(cls, institution):
|
||||||
|
|
||||||
sql = """
|
sql = """
|
||||||
WITH RankedAnnotations AS (
|
WITH RankedProperties AS (
|
||||||
SELECT
|
SELECT
|
||||||
t1.value,
|
t1.value,
|
||||||
t1.key,
|
t1.key,
|
||||||
|
@ -197,30 +197,30 @@ class Device:
|
||||||
END,
|
END,
|
||||||
t1.created DESC
|
t1.created DESC
|
||||||
) AS row_num
|
) 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
|
LEFT JOIN lot_devicelot AS t2 ON t1.value = t2.device_id
|
||||||
WHERE t2.device_id IS NULL
|
WHERE t2.device_id IS NULL
|
||||||
AND t1.owner_id = {institution}
|
AND t1.owner_id = {institution}
|
||||||
AND t1.type = {type}
|
And t1.type = '{type}'
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(DISTINCT value)
|
COUNT(DISTINCT value)
|
||||||
FROM
|
FROM
|
||||||
RankedAnnotations
|
RankedProperties
|
||||||
WHERE
|
WHERE
|
||||||
row_num = 1
|
row_num = 1
|
||||||
""".format(
|
""".format(
|
||||||
institution=institution.id,
|
institution=institution.id,
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Property.Type.SYSTEM,
|
||||||
)
|
)
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
return cursor.fetchall()[0][0]
|
return cursor.fetchall()[0][0]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_annotation_from_uuid(cls, uuid, institution):
|
def get_properties_from_uuid(cls, uuid, institution):
|
||||||
sql = """
|
sql = """
|
||||||
WITH RankedAnnotations AS (
|
WITH RankedProperties AS (
|
||||||
SELECT
|
SELECT
|
||||||
t1.value,
|
t1.value,
|
||||||
t1.key,
|
t1.key,
|
||||||
|
@ -234,29 +234,29 @@ class Device:
|
||||||
END,
|
END,
|
||||||
t1.created DESC
|
t1.created DESC
|
||||||
) AS row_num
|
) 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
|
LEFT JOIN lot_devicelot AS t2 ON t1.value = t2.device_id
|
||||||
WHERE t2.device_id IS NULL
|
WHERE t2.device_id IS NULL
|
||||||
AND t1.owner_id = {institution}
|
AND t1.owner_id = {institution}
|
||||||
AND t1.type = {type}
|
AND t1.type = '{type}'
|
||||||
AND t1.uuid = '{uuid}'
|
AND t1.uuid = '{uuid}'
|
||||||
)
|
)
|
||||||
SELECT DISTINCT
|
SELECT DISTINCT
|
||||||
value
|
value
|
||||||
FROM
|
FROM
|
||||||
RankedAnnotations
|
RankedProperties
|
||||||
WHERE
|
WHERE
|
||||||
row_num = 1;
|
row_num = 1;
|
||||||
""".format(
|
""".format(
|
||||||
uuid=uuid.replace("-", ""),
|
uuid=uuid.replace("-", ""),
|
||||||
institution=institution.id,
|
institution=institution.id,
|
||||||
type=Annotation.Type.SYSTEM,
|
type=Property.Type.SYSTEM,
|
||||||
)
|
)
|
||||||
|
|
||||||
annotations = []
|
properties = []
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
annotations = cursor.fetchall()
|
properties = cursor.fetchall()
|
||||||
|
|
||||||
return cls(id=annotations[0][0])
|
return cls(id=annotations[0][0])
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ class Evidence:
|
||||||
def get_all(cls, user):
|
def get_all(cls, user):
|
||||||
return SystemProperty.objects.filter(
|
return SystemProperty.objects.filter(
|
||||||
owner=user.institution,
|
owner=user.institution,
|
||||||
type=SystemProperty.Type.SYSTEM,
|
type=Property.Type.SYSTEM,
|
||||||
key="hidalgo1",
|
key="hidalgo1",
|
||||||
).order_by("-created").values_list("uuid", "created").distinct()
|
).order_by("-created").values_list("uuid", "created").distinct()
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ from django.views.generic.edit import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from dashboard.mixins import DashboardView, Http403
|
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 (
|
from evidence.forms import (
|
||||||
UploadForm,
|
UploadForm,
|
||||||
UserTagForm,
|
UserTagForm,
|
||||||
|
|
|
@ -76,7 +76,7 @@ def create_property(doc, user, commit=False):
|
||||||
'uuid': doc['uuid'],
|
'uuid': doc['uuid'],
|
||||||
'owner': user.institution,
|
'owner': user.institution,
|
||||||
'user': user,
|
'user': user,
|
||||||
'type': Annotation.Type.SYSTEM,
|
'type': Property.Type.SYSTEM,
|
||||||
'key': 'CUSTOMER_ID',
|
'key': 'CUSTOMER_ID',
|
||||||
'value': doc['CUSTOMER_ID'],
|
'value': doc['CUSTOMER_ID'],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue