Compare commits

...

3 Commits

7 changed files with 18 additions and 17 deletions

View File

@ -96,7 +96,7 @@ class SearchView(InventaryMixin):
qry |= Q(value__startswith=i) qry |= Q(value__startswith=i)
chids = SystemProperty.objects.filter( chids = SystemProperty.objects.filter(
type=Annotation.Type.SYSTEM, type=Property.Type.SYSTEM,
owner=self.request.user.institution owner=self.request.user.institution
).filter( ).filter(
qry qry

View File

@ -59,7 +59,7 @@ class BaseDeviceFormSet(forms.BaseFormSet):
path_name = save_in_disk(doc, self.user.institution.name, place="placeholder") path_name = save_in_disk(doc, self.user.institution.name, place="placeholder")
create_index(doc, self.user) create_index(doc, self.user)
create_annotation(doc, user, commit=commit) create_property(doc, user, commit=commit)
move_json(path_name, self.user.institution.name, place="placeholder") move_json(path_name, self.user.institution.name, place="placeholder")
return doc return doc

View File

@ -95,17 +95,18 @@ class Device:
key__in=algos, key__in=algos,
).values_list("value", flat=True))) ).values_list("value", flat=True)))
def get_properties(self): def get_evidences(self):
if not self.uuids: if not self.uuids:
self.get_uuids() self.get_uuids()
self.properties = [SystemProperty(u) for u in self.uuids] self.evidences = [Evidence(u) for u in self.uuids]
def get_last_evidence(self): def get_last_evidence(self):
properties = self.get_properties() properties = self.get_properties()
if not properties.count(): if not properties.count():
return return
property = property.first() property = properties.first()
self.last_evidence = Evidence(property.uuid) self.last_evidence = Evidence(property.uuid)
def is_eraseserver(self): def is_eraseserver(self):
@ -135,7 +136,7 @@ class Device:
def get_unassigned(cls, institution, offset=0, limit=None): def get_unassigned(cls, institution, offset=0, limit=None):
sql = """ sql = """
WITH RankedAnnotations AS ( WITH RankedProperties AS (
SELECT SELECT
t1.value, t1.value,
t1.key, t1.key,
@ -158,7 +159,7 @@ class Device:
SELECT DISTINCT SELECT DISTINCT
value value
FROM FROM
RankedAnnotations RankedProperties
WHERE WHERE
row_num = 1 row_num = 1
""".format( """.format(
@ -258,7 +259,7 @@ class Device:
cursor.execute(sql) cursor.execute(sql)
properties = cursor.fetchall() properties = cursor.fetchall()
return cls(id=annotations[0][0]) return cls(id=properties[0][0])
@property @property
def is_websnapshot(self): def is_websnapshot(self):

View File

@ -179,17 +179,17 @@ class AddUserPropertyView(DashboardView, CreateView):
form.instance.owner = self.request.user.institution form.instance.owner = self.request.user.institution
form.instance.user = self.request.user form.instance.user = self.request.user
form.instance.uuid = self.annotation.uuid form.instance.uuid = self.annotation.uuid
form.instance.type = Annotation.Type.USER form.instance.type = Property.Type.USER
response = super().form_valid(form) response = super().form_valid(form)
return response return response
def get_form_kwargs(self): def get_form_kwargs(self):
pk = self.kwargs.get('pk') pk = self.kwargs.get('pk')
institution = self.request.user.institution institution = self.request.user.institution
self.annotation = Annotation.objects.filter( self.annotation = SystemProperty.objects.filter(
owner=institution, owner=institution,
value=pk, value=pk,
type=Annotation.Type.SYSTEM type=Property.Type.SYSTEM
).first() ).first()
if not self.annotation: if not self.annotation:
@ -222,7 +222,7 @@ class AddDocumentView(DashboardView, CreateView):
self.annotation = SystemProperty.objects.filter( self.annotation = SystemProperty.objects.filter(
owner=institution, owner=institution,
value=pk, value=pk,
type=Annotation.Type.SYSTEM type=Property.Type.SYSTEM
).first() ).first()
if not self.annotation: if not self.annotation:

View File

@ -164,7 +164,7 @@ class ImportForm(forms.Form):
table = [] table = []
for row in self.rows: for row in self.rows:
doc = create_doc(row) doc = create_doc(row)
annotation = create_annotation(doc, self.user) annotation = create_property(doc, self.user)
table.append((doc, annotation)) table.append((doc, annotation))
if commit: if commit:
@ -222,7 +222,7 @@ class EraseServerForm(forms.Form):
if self.instance: if self.instance:
return return
Annotation.objects.create( SystemProperty.objects.create(
uuid=self.uuid, uuid=self.uuid,
type=Annotation.Type.ERASE_SERVER, type=Annotation.Type.ERASE_SERVER,
key='ERASE_SERVER', key='ERASE_SERVER',

View File

@ -5,7 +5,7 @@ import logging
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
from utils.device import create_annotation, create_doc, create_index from utils.device import create_property, create_doc, create_index
from user.models import Institution from user.models import Institution
from evidence.parse import Build from evidence.parse import Build
@ -70,7 +70,7 @@ class Command(BaseCommand):
def build_placeholder(self, s, user, f_path): def build_placeholder(self, s, user, f_path):
try: try:
create_index(s, user) create_index(s, user)
create_annotation(s, user, commit=True) create_property(s, user, commit=True)
except Exception as err: except Exception as err:
txt = "In placeholder %s \n%s" txt = "In placeholder %s \n%s"
logger.warning(txt, f_path, err) logger.warning(txt, f_path, err)

View File

@ -6,7 +6,7 @@ from dmidecode import DMIParse
from json_repair import repair_json from json_repair import repair_json
from evidence.parse_details import get_lshw_child from evidence.parse_details import get_lshw_child
from evidence.models import SystemProperty from evidence.models import SystemProperty, Property
from evidence.xapian import index from evidence.xapian import index
from utils.constants import CHASSIS_DH from utils.constants import CHASSIS_DH