WIP: rework/properties #31

Draft
rskthomas wants to merge 20 commits from rework/properties into main
6 changed files with 14 additions and 13 deletions
Showing only changes of commit b7d7b9041d - Show all commits

View File

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

View File

@ -59,7 +59,7 @@ class BaseDeviceFormSet(forms.BaseFormSet):
path_name = save_in_disk(doc, self.user.institution.name, place="placeholder")
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")
return doc

View File

@ -105,7 +105,8 @@ class Device:
properties = self.get_properties()
if not properties.count():
return
property = property.first()
property = properties.first()
self.last_evidence = Evidence(property.uuid)
def is_eraseserver(self):
@ -135,7 +136,7 @@ class Device:
def get_unassigned(cls, institution, offset=0, limit=None):
sql = """
WITH RankedAnnotations AS (
WITH RankedProperties AS (
SELECT
t1.value,
t1.key,
@ -158,7 +159,7 @@ class Device:
SELECT DISTINCT
value
FROM
RankedAnnotations
RankedProperties
WHERE
row_num = 1
""".format(
@ -258,7 +259,7 @@ class Device:
cursor.execute(sql)
properties = cursor.fetchall()
return cls(id=annotations[0][0])
return cls(id=properties[0][0])
@property
def is_websnapshot(self):

View File

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

View File

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

View File

@ -70,7 +70,7 @@ class Command(BaseCommand):
def build_placeholder(self, s, user, f_path):
try:
create_index(s, user)
create_annotation(s, user, commit=True)
create_property(s, user, commit=True)
except Exception as err:
txt = "In placeholder %s \n%s"
logger.warning(txt, f_path, err)