Skip to content

Commit

Permalink
Merge pull request #4 from girder/fix-scan-decision
Browse files Browse the repository at this point in the history
Fix Scan decision field values
  • Loading branch information
dchiquito authored May 3, 2021
2 parents 2791535 + 7bf86fb commit f3c8264
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
18 changes: 18 additions & 0 deletions miqa/core/migrations/0004_alter_scan_decision.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
18 changes: 9 additions & 9 deletions miqa/core/models/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand All @@ -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)

0 comments on commit f3c8264

Please sign in to comment.