From 9bd368b6ad2e98c811abf1793debb066b7896365 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Wed, 21 Feb 2024 12:03:01 +0100 Subject: [PATCH 01/32] Make risk scenario strength of knowledge optional "--" maps to None --- backend/core/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/core/models.py b/backend/core/models.py index 3999bc642..75e0a63df 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -857,7 +857,6 @@ class RiskScenario(AbstractBaseModel, NameDescriptionMixin): ] SOK_OPTIONS = [ - ("--", _("--")), ("0", _("Low")), ("1", _("Medium")), ("2", _("High")), @@ -938,7 +937,8 @@ class RiskScenario(AbstractBaseModel, NameDescriptionMixin): strength_of_knowledge = models.CharField( max_length=20, choices=SOK_OPTIONS, - default="--", + null=True, + blank=True, verbose_name=_("Strength of Knowledge"), ) justification = models.CharField( From 68f12a7bd7eaad268b02a8bd4848785478c40142 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Wed, 21 Feb 2024 12:19:51 +0100 Subject: [PATCH 02/32] Create /risk-scenarios/strength_of_knowledge endpoint --- backend/core/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/core/views.py b/backend/core/views.py index 48a7d62e2..e95be76d0 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -657,6 +657,10 @@ class RiskScenarioViewSet(BaseModelViewSet): def treatment(self, request): return Response(dict(RiskScenario.TREATMENT_OPTIONS)) + @action(detail=False, name="Get strength of knowledge choices") + def strength_of_knowledge(self, request): + return Response(dict(RiskScenario.SOK_OPTIONS)) + @action(detail=True, name="Get probability choices") def probability(self, request, pk): undefined = dict([(-1, "--")]) From 408e416daf34c5411c1de39fbf771a622d15a0cb Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Wed, 21 Feb 2024 12:20:06 +0100 Subject: [PATCH 03/32] Update Select component default value --- frontend/src/lib/components/Forms/Select.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/components/Forms/Select.svelte b/frontend/src/lib/components/Forms/Select.svelte index 3c0b13da0..6810b0440 100644 --- a/frontend/src/lib/components/Forms/Select.svelte +++ b/frontend/src/lib/components/Forms/Select.svelte @@ -55,8 +55,8 @@ {...$constraints} {...$$restProps} > - {#if !$constraints?.required} - + {#if !$constraints?.required && !options.find((o) => o.label === '--')} + {/if} {#each options as option}