From 31e745b79c8d90cfbfb0362e1e30384bf3c7b96d Mon Sep 17 00:00:00 2001 From: Daniel Chiquito Date: Mon, 3 May 2021 13:28:38 -0400 Subject: [PATCH] Fix Scan decision field values I inadvertently switched the name and the value when using `ScanDecision` to define `Scan.decision` resulting in the labels being saved to the DB instead of the enum names. --- .../migrations/0004_alter_scan_decision.py | 18 ++++++++++++++++++ miqa/core/models/scan.py | 18 +++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 miqa/core/migrations/0004_alter_scan_decision.py diff --git a/miqa/core/migrations/0004_alter_scan_decision.py b/miqa/core/migrations/0004_alter_scan_decision.py new file mode 100644 index 00000000..b054bdc1 --- /dev/null +++ b/miqa/core/migrations/0004_alter_scan_decision.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2 on 2021-05-03 17:09 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0003_default_session'), + ] + + operations = [ + migrations.AlterField( + model_name='scan', + name='decision', + field=models.CharField(choices=[('NONE', '-'), ('GOOD', 'Good'), ('BAD', 'Bad'), ('USABLE_EXTRA', 'Usable extra')], default='NONE', max_length=20), + ), + ] diff --git a/miqa/core/models/scan.py b/miqa/core/models/scan.py index d110af05..82b1bea7 100644 --- a/miqa/core/models/scan.py +++ b/miqa/core/models/scan.py @@ -13,19 +13,19 @@ class ScanDecision(Enum): @classmethod def from_rating(cls, rating: str) -> str: return { - '': cls.NONE.value, - '0': cls.BAD.value, - '1': cls.GOOD.value, - '2': cls.USABLE_EXTRA.value, + '': cls.NONE.name, + '0': cls.BAD.name, + '1': cls.GOOD.name, + '2': cls.USABLE_EXTRA.name, }[rating] @classmethod def to_rating(cls, decision: str) -> str: return { - cls.NONE.value: '', - cls.BAD.value: '0', - cls.GOOD.value: '1', - cls.USABLE_EXTRA.value: '2', + cls.NONE.name: '', + cls.BAD.name: '0', + cls.GOOD.name: '1', + cls.USABLE_EXTRA.name: '2', }[decision] @@ -45,7 +45,7 @@ class Meta: scan_type = models.CharField(max_length=255, blank=False) decision = models.CharField( max_length=20, - default=ScanDecision.NONE.value, + default=ScanDecision.NONE.name, choices=[(tag.name, tag.value) for tag in ScanDecision], ) note = models.TextField(max_length=3000, blank=True)