select your algorithm

This commit is contained in:
Cayo Puigdefabregas 2025-02-18 12:41:04 +01:00 committed by pedro
parent d994d302a0
commit 85a3575728
4 changed files with 41 additions and 16 deletions

View file

@ -218,7 +218,8 @@ class InstitutionView(AdminView, UpdateView):
"logo",
"location",
"responsable_person",
"supervisor_person"
"supervisor_person",
"algorithm"
)
def get_form_kwargs(self):

View file

@ -148,13 +148,13 @@ class Device:
ORDER BY
CASE
WHEN t1.key = 'CUSTOM_ID' THEN 1
WHEN t1.key = 'ereuse24' THEN 2
ELSE 3
WHEN t1.key = '{algorithm}' THEN 2
END,
t1.created DESC
) AS row_num
FROM evidence_systemproperty AS t1
WHERE t1.owner_id = {institution}
AND t1.key IN ('CUSTOM_ID', '{algorithm}')
)
SELECT DISTINCT
value
@ -164,6 +164,7 @@ class Device:
row_num = 1
""".format(
institution=institution.id,
algorithm=institution.algorithm,
)
if limit:
sql += " limit {} offset {}".format(int(limit), int(offset))
@ -192,14 +193,14 @@ class Device:
ORDER BY
CASE
WHEN t1.key = 'CUSTOM_ID' THEN 1
WHEN t1.key = 'ereuse24' THEN 2
ELSE 3
WHEN t1.key = '{algorithm}' THEN 2
END,
t1.created DESC
) AS row_num
FROM evidence_systemproperty AS t1
WHERE t1.owner_id = {institution}
AND t1.key IN ('CUSTOM_ID', '{algorithm}')
)
SELECT
COUNT(DISTINCT value)
@ -208,7 +209,8 @@ class Device:
WHERE
row_num = 1
""".format(
institution=institution.id
institution=institution.id,
algorithm=institution.algorithm
)
with connection.cursor() as cursor:
cursor.execute(sql)
@ -228,8 +230,7 @@ class Device:
ORDER BY
CASE
WHEN t1.key = 'CUSTOM_ID' THEN 1
WHEN t1.key = 'ereuse24' THEN 2
ELSE 3
WHEN t1.key = '{algorithm}' THEN 2
END,
t1.created DESC
) AS row_num
@ -237,6 +238,7 @@ class Device:
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.key IN ('CUSTOM_ID', '{algorithm}')
)
SELECT DISTINCT
value
@ -246,6 +248,7 @@ class Device:
row_num = 1
""".format(
institution=institution.id,
algorithm=institution.algorithm
)
if limit:
sql += " limit {} offset {}".format(int(limit), int(offset))
@ -274,8 +277,7 @@ class Device:
ORDER BY
CASE
WHEN t1.key = 'CUSTOM_ID' THEN 1
WHEN t1.key = 'ereuse24' THEN 2
ELSE 3
WHEN t1.key = '{algorithm}' THEN 2
END,
t1.created DESC
) AS row_num
@ -283,6 +285,7 @@ class Device:
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.key IN ('CUSTOM_ID', '{algorithm}')
)
SELECT
COUNT(DISTINCT value)
@ -292,6 +295,7 @@ class Device:
row_num = 1
""".format(
institution=institution.id,
algorithm=institution.algorithm
)
with connection.cursor() as cursor:
cursor.execute(sql)
@ -309,16 +313,14 @@ class Device:
ORDER BY
CASE
WHEN t1.key = 'CUSTOM_ID' THEN 1
WHEN t1.key = 'ereuse24' THEN 2
ELSE 3
WHEN t1.key = '{algorithm}' THEN 2
END,
t1.created DESC
) 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}
WHERE t1.owner_id = {institution}
AND t1.uuid = '{uuid}'
AND t1.key IN ('CUSTOM_ID', '{algorithm}')
)
SELECT DISTINCT
value
@ -329,6 +331,7 @@ class Device:
""".format(
uuid=uuid.replace("-", ""),
institution=institution.id,
algorithm=institution.algorithm,
)
properties = []

View file

@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2025-02-18 08:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('user', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='institution',
name='algorithm',
field=models.CharField(choices=[('ereuse24', 'ereuse24'), ('ereuse22', 'ereuse22')], default='ereuse24', max_length=30),
),
]

View file

@ -1,8 +1,10 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser
from utils.constants import ALGOS
# Create your models here.
ALGORITHMS = [(x, x) for x in ALGOS.keys()]
class Institution(models.Model):
@ -27,6 +29,7 @@ class Institution(models.Model):
blank=True,
null=True
)
algorithm = models.CharField(max_length=30, choices=ALGORITHMS, default='ereuse24')
class UserManager(BaseUserManager):