diff --git a/admin/views.py b/admin/views.py index 345227d..f7755d6 100644 --- a/admin/views.py +++ b/admin/views.py @@ -218,7 +218,8 @@ class InstitutionView(AdminView, UpdateView): "logo", "location", "responsable_person", - "supervisor_person" + "supervisor_person", + "algorithm" ) def get_form_kwargs(self): diff --git a/device/models.py b/device/models.py index d773227..7aec217 100644 --- a/device/models.py +++ b/device/models.py @@ -149,13 +149,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 @@ -165,6 +165,7 @@ class Device: row_num = 1 """.format( institution=institution.id, + algorithm=institution.algorithm, ) if limit: sql += " limit {} offset {}".format(int(limit), int(offset)) @@ -193,14 +194,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) @@ -209,7 +210,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) @@ -229,8 +231,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 @@ -238,6 +239,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 @@ -247,6 +249,7 @@ class Device: row_num = 1 """.format( institution=institution.id, + algorithm=institution.algorithm ) if limit: sql += " limit {} offset {}".format(int(limit), int(offset)) @@ -275,8 +278,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 @@ -284,6 +286,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) @@ -293,6 +296,7 @@ class Device: row_num = 1 """.format( institution=institution.id, + algorithm=institution.algorithm ) with connection.cursor() as cursor: cursor.execute(sql) @@ -310,16 +314,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 @@ -330,6 +332,7 @@ class Device: """.format( uuid=uuid.replace("-", ""), institution=institution.id, + algorithm=institution.algorithm, ) properties = [] diff --git a/user/migrations/0002_institution_algorithm.py b/user/migrations/0002_institution_algorithm.py new file mode 100644 index 0000000..3f4660d --- /dev/null +++ b/user/migrations/0002_institution_algorithm.py @@ -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), + ), + ] diff --git a/user/models.py b/user/models.py index 5fd8424..a289270 100644 --- a/user/models.py +++ b/user/models.py @@ -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):