From 1dff57d47b6ee713ccfcfeaa28ea1f7356bd9fa2 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Fri, 20 Dec 2024 13:27:39 +0100 Subject: [PATCH] feat: add activity choices --- .../migrations/0009_alter_roto_activity.py | 19 +++++++++++++++++++ backend/ebios_rm/models.py | 12 +++++++++++- backend/ebios_rm/serializers.py | 1 + backend/ebios_rm/views.py | 4 ++++ .../Forms/ModelForm/RoToForm.svelte | 11 ++--------- frontend/src/lib/utils/crud.ts | 3 ++- .../(internal)/ro-to/[id=uuid]/+page.svelte | 2 +- 7 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 backend/ebios_rm/migrations/0009_alter_roto_activity.py diff --git a/backend/ebios_rm/migrations/0009_alter_roto_activity.py b/backend/ebios_rm/migrations/0009_alter_roto_activity.py new file mode 100644 index 000000000..3705c2d84 --- /dev/null +++ b/backend/ebios_rm/migrations/0009_alter_roto_activity.py @@ -0,0 +1,19 @@ +# Generated by Django 5.1.4 on 2024-12-20 12:16 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ebios_rm', '0008_remove_attackpath_ro_to_couple_strategicscenario_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='roto', + name='activity', + field=models.PositiveSmallIntegerField(choices=[(0, 'undefined'), (1, 'very_low'), (2, 'low'), (3, 'moderate'), (4, 'important')], default=0, validators=[django.core.validators.MaxValueValidator(4)], verbose_name='Activity'), + ), + ] diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index ba5884409..584b70dff 100644 --- a/backend/ebios_rm/models.py +++ b/backend/ebios_rm/models.py @@ -272,6 +272,13 @@ class Resources(models.IntegerChoices): IMPORTANT = 3, "important" UNLIMITED = 4, "unlimited" + class Activity(models.IntegerChoices): + UNDEFINED = 0, "undefined" + VERY_LOW = 1, "very_low" + LOW = 2, "low" + MODERATE = 3, "moderate" + IMPORTANT = 4, "important" + class Pertinence(models.IntegerChoices): UNDEFINED = 0, "undefined" IRRELAVANT = 1, "irrelevant" @@ -306,7 +313,10 @@ class Pertinence(models.IntegerChoices): default=Resources.UNDEFINED, ) activity = models.PositiveSmallIntegerField( - verbose_name=_("Activity"), default=0, validators=[MaxValueValidator(4)] + verbose_name=_("Activity"), + choices=Activity.choices, + default=Activity.UNDEFINED, + validators=[MaxValueValidator(4)], ) is_selected = models.BooleanField(verbose_name=_("Is selected"), default=False) justification = models.TextField(verbose_name=_("Justification"), blank=True) diff --git a/backend/ebios_rm/serializers.py b/backend/ebios_rm/serializers.py index b23c78876..908a63477 100644 --- a/backend/ebios_rm/serializers.py +++ b/backend/ebios_rm/serializers.py @@ -97,6 +97,7 @@ class RoToReadSerializer(BaseModelSerializer): motivation = serializers.CharField(source="get_motivation_display") resources = serializers.CharField(source="get_resources_display") + activity = serializers.CharField(source="get_activity_display") pertinence = serializers.CharField(source="get_pertinence") class Meta: diff --git a/backend/ebios_rm/views.py b/backend/ebios_rm/views.py index c1684c5b0..59535e697 100644 --- a/backend/ebios_rm/views.py +++ b/backend/ebios_rm/views.py @@ -139,6 +139,10 @@ def motivation(self, request): @action(detail=False, name="Get resources choices") def resources(self, request): return Response(dict(RoTo.Resources.choices)) + + @action(detail=False, name="Get activity choices") + def activity(self, request): + return Response(dict(RoTo.Activity.choices)) class StakeholderViewSet(BaseModelViewSet): diff --git a/frontend/src/lib/components/Forms/ModelForm/RoToForm.svelte b/frontend/src/lib/components/Forms/ModelForm/RoToForm.svelte index a78db0a56..ac229b4f6 100644 --- a/frontend/src/lib/components/Forms/ModelForm/RoToForm.svelte +++ b/frontend/src/lib/components/Forms/ModelForm/RoToForm.svelte @@ -96,16 +96,9 @@ cacheLock={cacheLocks['resources']} bind:cachedValue={formDataCache['resources']} /> - - {m.activity()} = - {roto.activity} + {safeTranslate(roto.activity)}