diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2020-02-25 08:19:35 +0000 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2020-02-25 08:19:35 +0000 |
commit | 9269f3c3798b677b4e46abcc5df5f869c9cb9164 (patch) | |
tree | b35b4b6b0e7407e6056084b8e4ad19614e612478 /ctrack | |
parent | fdf52fb15cb594f8717b852c33a292149a21b8b8 (diff) |
populate now does gradings
Diffstat (limited to '')
-rw-r--r-- | ctrack/caf/admin.py | 9 | ||||
-rw-r--r-- | ctrack/caf/migrations/0008_auto_20200225_0722.py | 46 | ||||
-rw-r--r-- | ctrack/caf/migrations/0009_grading_type.py | 19 | ||||
-rw-r--r-- | ctrack/caf/migrations/0010_auto_20200225_0747.py | 18 | ||||
-rw-r--r-- | ctrack/caf/models.py | 34 | ||||
-rw-r--r-- | ctrack/caf/tests/factories.py | 22 | ||||
-rw-r--r-- | ctrack/organisations/management/commands/populate_db.py | 9 |
7 files changed, 121 insertions, 36 deletions
diff --git a/ctrack/caf/admin.py b/ctrack/caf/admin.py index 139b013..b0f1218 100644 --- a/ctrack/caf/admin.py +++ b/ctrack/caf/admin.py @@ -1,8 +1,6 @@ from django.contrib import admin -from .models import CAF, CAFFileStore, DocumentFile, Ranking -from .models import ConfidenceAssessment -from .models import EssentialService +from .models import CAF, CAFFileStore, DocumentFile, Grading, EssentialService class EssentialServiceListAdmin(admin.ModelAdmin): @@ -19,12 +17,11 @@ class EssentialServiceAdmin(admin.StackedInline): class CAFAdmin(admin.ModelAdmin): model = CAF inlines = [EssentialServiceAdmin] - list_display = ["owner", "triage_ranking", "confidence_assessment", "file"] + list_display = ["owner", "triage_grading", "confidence_grading", "file"] admin.site.register(CAF, CAFAdmin) admin.site.register(CAFFileStore) admin.site.register(DocumentFile) -admin.site.register(Ranking) -admin.site.register(ConfidenceAssessment) +admin.site.register(Grading) admin.site.register(EssentialService, EssentialServiceListAdmin) diff --git a/ctrack/caf/migrations/0008_auto_20200225_0722.py b/ctrack/caf/migrations/0008_auto_20200225_0722.py new file mode 100644 index 0000000..e1e0c95 --- /dev/null +++ b/ctrack/caf/migrations/0008_auto_20200225_0722.py @@ -0,0 +1,46 @@ +# Generated by Django 2.2.9 on 2020-02-25 07:22 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('caf', '0007_auto_20200221_2122'), + ] + + operations = [ + migrations.CreateModel( + name='Grading', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('descriptor', models.CharField(max_length=2)), + ('description', models.TextField(max_length=250)), + ], + ), + migrations.RemoveField( + model_name='caf', + name='confidence_assessment', + ), + migrations.RemoveField( + model_name='caf', + name='triage_ranking', + ), + migrations.DeleteModel( + name='ConfidenceAssessment', + ), + migrations.DeleteModel( + name='Ranking', + ), + migrations.AddField( + model_name='caf', + name='confidence_grading', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='confidence_grading', to='caf.Grading'), + ), + migrations.AddField( + model_name='caf', + name='triage_grading', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='triage_grading', to='caf.Grading'), + ), + ] diff --git a/ctrack/caf/migrations/0009_grading_type.py b/ctrack/caf/migrations/0009_grading_type.py new file mode 100644 index 0000000..3c63218 --- /dev/null +++ b/ctrack/caf/migrations/0009_grading_type.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.9 on 2020-02-25 07:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('caf', '0008_auto_20200225_0722'), + ] + + operations = [ + migrations.AddField( + model_name='grading', + name='type', + field=models.CharField(choices=[('CONFIDENCE', 'Confidence'), ('QUALITY', 'Quality'), ('MISC', 'Misc')], default='MISC', help_text='Type of grading', max_length=20), + preserve_default=False, + ), + ] diff --git a/ctrack/caf/migrations/0010_auto_20200225_0747.py b/ctrack/caf/migrations/0010_auto_20200225_0747.py new file mode 100644 index 0000000..7104bb8 --- /dev/null +++ b/ctrack/caf/migrations/0010_auto_20200225_0747.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.9 on 2020-02-25 07:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('caf', '0009_grading_type'), + ] + + operations = [ + migrations.AlterField( + model_name='grading', + name='descriptor', + field=models.CharField(help_text='Q1, C1, etc', max_length=2), + ), + ] diff --git a/ctrack/caf/models.py b/ctrack/caf/models.py index 14b2650..401bf25 100644 --- a/ctrack/caf/models.py +++ b/ctrack/caf/models.py @@ -2,32 +2,12 @@ from django.db import models from ctrack.organisations.models import Organisation -# TODO - thinking about whether TriageAssessment can be converted into an inherited class -# e.g. we inherit from -# class Assessment(models.Model): -# descriptor = models.CharField(max_length=100) -# date_entered = models.DateTimeField(auto_now_add=True) -# modified = models.DateTimeField(auto_now=True) -# -# class Meta: -# abstract = True - - -class Ranking(models.Model): - RANKING_TYPE = [(1, "Triage"), (2, "First Assessment"), (3, "Validation")] - descriptor = models.CharField(max_length=100) - description = models.TextField(max_length=250) - type = models.IntegerField(choices=RANKING_TYPE, default=1) - - - def __str__(self): - return self.descriptor - -class ConfidenceAssessment(models.Model): - RANKING_TYPE = [("GOOD", "Good"), ("BAD", "Bad"), ("OK", "OK")] - descriptor = models.CharField(max_length=10, choices=RANKING_TYPE, default=1) +class Grading(models.Model): + GRADING_TYPE = [("CONFIDENCE", "Confidence"), ("QUALITY", "Quality"), ("MISC", "Misc")] + descriptor = models.CharField(max_length=2, help_text="Q1, C1, etc") description = models.TextField(max_length=250) + type = models.CharField(max_length=20, choices=GRADING_TYPE, help_text="Type of grading") def __str__(self): return self.descriptor @@ -81,8 +61,10 @@ class EssentialService(models.Model): class CAF(models.Model): owner = models.ForeignKey(Organisation, on_delete=models.CASCADE) - triage_ranking = models.ForeignKey(Ranking, on_delete=models.CASCADE, blank=True, null=True) - confidence_assessment = models.ForeignKey(ConfidenceAssessment, on_delete=models.CASCADE, blank=True, null=True) + triage_grading = models.ForeignKey(Grading, on_delete=models.CASCADE, blank=True, null=True, + related_name="triage_grading") + confidence_grading = models.ForeignKey(Grading, on_delete=models.CASCADE, blank=True, null=True, + related_name="confidence_grading") file = models.ForeignKey(DocumentFile, on_delete=models.CASCADE, blank=True, null=True) class Meta: diff --git a/ctrack/caf/tests/factories.py b/ctrack/caf/tests/factories.py index ec02bce..bae0d9c 100644 --- a/ctrack/caf/tests/factories.py +++ b/ctrack/caf/tests/factories.py @@ -1,17 +1,31 @@ import factory -from ctrack.caf.models import CAF, EssentialService +from factory import Faker + +from ctrack.caf.models import CAF, EssentialService, Grading from ctrack.organisations.tests.factories import PersonFactory class EssentialServiceFactory(factory.DjangoModelFactory): """Factory for Essential Services.""" - model = EssentialService + + class Meta: + model = EssentialService + + +class GradingFactory(factory.DjangoModelFactory): + descriptor = factory.Iterator(["Q1", "Q2", "Q3", "Q4", "Q5", "C1", "C2", "C3", "C4", "C5"]) + description = Faker("text", max_nb_chars=100, ext_word_list=None) + type = factory.Iterator(Grading.GRADING_TYPE, getter=lambda g: g[0]) + + class Meta: + model = Grading class CAFFactory(factory.DjangoModelFactory): """Factory for CAFs.""" - model = CAF owner = factory.SubFactory(PersonFactory) # triage_ranking = factory.SubFactory(TriageRankingFactory) -# TODO - we want an abstract Ranking + + class Meta: + model = CAF diff --git a/ctrack/organisations/management/commands/populate_db.py b/ctrack/organisations/management/commands/populate_db.py index db45d50..3335a11 100644 --- a/ctrack/organisations/management/commands/populate_db.py +++ b/ctrack/organisations/management/commands/populate_db.py @@ -3,6 +3,7 @@ from random import randint, choice from django.core.management import BaseCommand from django.core.management import CommandParser +from ctrack.caf.tests.factories import GradingFactory from ctrack.organisations.models import AddressType from ctrack.organisations.models import Mode from ctrack.organisations.models import Submode @@ -103,3 +104,11 @@ class Command(BaseCommand): ee1 = EngagementEventFactory.create(type=etf1, user=user, participants=[p1, p2]) ee2 = EngagementEventFactory.create(type=etf2, user=user, participants=[p3]) + + # Quality gradings + for g in ["Q1", "Q2", "Q3", "Q4", "Q5"]: + GradingFactory.create(descriptor=g, type="QUALITY") + + # Confidence gradings + for g in ["C1", "C2", "C3", "C4", "C5"]: + GradingFactory.create(descriptor=g, type="CONFIDENCE") |