select your algorithm

This commit is contained in:
Cayo Puigdefabregas 2025-02-18 12:41:04 +01:00
parent 5fdaeb690a
commit 2297d0b5bb
4 changed files with 41 additions and 16 deletions

View file

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

View file

@ -148,13 +148,13 @@ class Device:
ORDER BY ORDER BY
CASE CASE
WHEN t1.key = 'CUSTOM_ID' THEN 1 WHEN t1.key = 'CUSTOM_ID' THEN 1
WHEN t1.key = 'ereuse24' THEN 2 WHEN t1.key = '{algorithm}' THEN 2
ELSE 3
END, END,
t1.created DESC t1.created DESC
) AS row_num ) AS row_num
FROM evidence_systemproperty AS t1 FROM evidence_systemproperty AS t1
WHERE t1.owner_id = {institution} WHERE t1.owner_id = {institution}
AND t1.key IN ('CUSTOM_ID', '{algorithm}')
) )
SELECT DISTINCT SELECT DISTINCT
value value
@ -164,6 +164,7 @@ class Device:
row_num = 1 row_num = 1
""".format( """.format(
institution=institution.id, institution=institution.id,
algorithm=institution.algorithm,
) )
if limit: if limit:
sql += " limit {} offset {}".format(int(limit), int(offset)) sql += " limit {} offset {}".format(int(limit), int(offset))
@ -192,14 +193,14 @@ class Device:
ORDER BY ORDER BY
CASE CASE
WHEN t1.key = 'CUSTOM_ID' THEN 1 WHEN t1.key = 'CUSTOM_ID' THEN 1
WHEN t1.key = 'ereuse24' THEN 2 WHEN t1.key = '{algorithm}' THEN 2
ELSE 3
END, END,
t1.created DESC t1.created DESC
) AS row_num ) AS row_num
FROM evidence_systemproperty AS t1 FROM evidence_systemproperty AS t1
WHERE t1.owner_id = {institution} WHERE t1.owner_id = {institution}
AND t1.key IN ('CUSTOM_ID', '{algorithm}')
) )
SELECT SELECT
COUNT(DISTINCT value) COUNT(DISTINCT value)
@ -208,7 +209,8 @@ class Device:
WHERE WHERE
row_num = 1 row_num = 1
""".format( """.format(
institution=institution.id institution=institution.id,
algorithm=institution.algorithm
) )
with connection.cursor() as cursor: with connection.cursor() as cursor:
cursor.execute(sql) cursor.execute(sql)
@ -228,8 +230,7 @@ class Device:
ORDER BY ORDER BY
CASE CASE
WHEN t1.key = 'CUSTOM_ID' THEN 1 WHEN t1.key = 'CUSTOM_ID' THEN 1
WHEN t1.key = 'ereuse24' THEN 2 WHEN t1.key = '{algorithm}' THEN 2
ELSE 3
END, END,
t1.created DESC t1.created DESC
) AS row_num ) AS row_num
@ -237,6 +238,7 @@ class Device:
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.key IN ('CUSTOM_ID', '{algorithm}')
) )
SELECT DISTINCT SELECT DISTINCT
value value
@ -246,6 +248,7 @@ class Device:
row_num = 1 row_num = 1
""".format( """.format(
institution=institution.id, institution=institution.id,
algorithm=institution.algorithm
) )
if limit: if limit:
sql += " limit {} offset {}".format(int(limit), int(offset)) sql += " limit {} offset {}".format(int(limit), int(offset))
@ -274,8 +277,7 @@ class Device:
ORDER BY ORDER BY
CASE CASE
WHEN t1.key = 'CUSTOM_ID' THEN 1 WHEN t1.key = 'CUSTOM_ID' THEN 1
WHEN t1.key = 'ereuse24' THEN 2 WHEN t1.key = '{algorithm}' THEN 2
ELSE 3
END, END,
t1.created DESC t1.created DESC
) AS row_num ) AS row_num
@ -283,6 +285,7 @@ class Device:
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.key IN ('CUSTOM_ID', '{algorithm}')
) )
SELECT SELECT
COUNT(DISTINCT value) COUNT(DISTINCT value)
@ -292,6 +295,7 @@ class Device:
row_num = 1 row_num = 1
""".format( """.format(
institution=institution.id, institution=institution.id,
algorithm=institution.algorithm
) )
with connection.cursor() as cursor: with connection.cursor() as cursor:
cursor.execute(sql) cursor.execute(sql)
@ -309,16 +313,14 @@ class Device:
ORDER BY ORDER BY
CASE CASE
WHEN t1.key = 'CUSTOM_ID' THEN 1 WHEN t1.key = 'CUSTOM_ID' THEN 1
WHEN t1.key = 'ereuse24' THEN 2 WHEN t1.key = '{algorithm}' THEN 2
ELSE 3
END, END,
t1.created DESC t1.created DESC
) AS row_num ) AS row_num
FROM evidence_systemproperty AS t1 FROM evidence_systemproperty AS t1
LEFT JOIN lot_devicelot AS t2 ON t1.value = t2.device_id WHERE t1.owner_id = {institution}
WHERE t2.device_id IS NULL
AND t1.owner_id = {institution}
AND t1.uuid = '{uuid}' AND t1.uuid = '{uuid}'
AND t1.key IN ('CUSTOM_ID', '{algorithm}')
) )
SELECT DISTINCT SELECT DISTINCT
value value
@ -329,6 +331,7 @@ class Device:
""".format( """.format(
uuid=uuid.replace("-", ""), uuid=uuid.replace("-", ""),
institution=institution.id, institution=institution.id,
algorithm=institution.algorithm,
) )
properties = [] 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.db import models
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser 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): class Institution(models.Model):
@ -27,6 +29,7 @@ class Institution(models.Model):
blank=True, blank=True,
null=True null=True
) )
algorithm = models.CharField(max_length=30, choices=ALGORITHMS, default='ereuse24')
class UserManager(BaseUserManager): class UserManager(BaseUserManager):