diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-02-21 16:00:12 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-02-21 16:00:27 +0000 |
commit | abd22b0143661370aa29246d21389d5f0bf7abc3 (patch) | |
tree | cad94ede9241b19d8560aec3b7cae4f693272aa8 | |
parent | 46107b7539211adbe71ab25d319b5c1f744fe4c4 (diff) |
added first register models - engagement-related
Diffstat (limited to '')
-rw-r--r-- | ctrack/caf/admin.py | 2 | ||||
-rw-r--r-- | ctrack/caf/models.py | 1 | ||||
-rw-r--r-- | ctrack/register/admin.py | 19 | ||||
-rw-r--r-- | ctrack/register/migrations/0001_initial.py | 45 | ||||
-rw-r--r-- | ctrack/register/migrations/0002_auto_20200221_1527.py | 49 | ||||
-rw-r--r-- | ctrack/register/migrations/0003_engagementevent_short_description.py | 19 | ||||
-rw-r--r-- | ctrack/register/models.py | 55 |
7 files changed, 184 insertions, 6 deletions
diff --git a/ctrack/caf/admin.py b/ctrack/caf/admin.py index c0f416e..e423044 100644 --- a/ctrack/caf/admin.py +++ b/ctrack/caf/admin.py @@ -2,8 +2,6 @@ from django.contrib import admin from .models import CAF, CAFFileStore, DocumentFile, Ranking -# Register your models here. - admin.site.register(CAF) admin.site.register(CAFFileStore) admin.site.register(DocumentFile) diff --git a/ctrack/caf/models.py b/ctrack/caf/models.py index 6350871..aa70d98 100644 --- a/ctrack/caf/models.py +++ b/ctrack/caf/models.py @@ -47,6 +47,7 @@ class DocumentFile(models.Model): class CAF(models.Model): owner = models.ForeignKey(Organisation, on_delete=models.CASCADE) + # TODO: essential systems need to be tracked as entities essential_system = models.CharField(max_length=255, blank=True) triage_ranking = models.ForeignKey(Ranking, on_delete=models.CASCADE) file = models.ForeignKey(DocumentFile, on_delete=models.CASCADE, blank=True) diff --git a/ctrack/register/admin.py b/ctrack/register/admin.py index 5538909..8b4930e 100644 --- a/ctrack/register/admin.py +++ b/ctrack/register/admin.py @@ -1,3 +1,18 @@ -#from django.contrib import admin +from django.contrib import admin -# Register your models here. +from ctrack.register.models import EngagementEvent +from ctrack.register.models import EngagementType + + +class EngagementEventAdmin(admin.ModelAdmin): + model = EngagementEvent + list_display = ("type", "user", "date", "short_description", "response_date_requested") + + +class EngagementEventTypeAdmin(admin.ModelAdmin): + model = EngagementEventAdmin + list_display = ("descriptor", "enforcement_instrument", "regulation_reference") + + +admin.site.register(EngagementEvent, EngagementEventAdmin) +admin.site.register(EngagementType, EngagementEventTypeAdmin) diff --git a/ctrack/register/migrations/0001_initial.py b/ctrack/register/migrations/0001_initial.py new file mode 100644 index 0000000..2ac7241 --- /dev/null +++ b/ctrack/register/migrations/0001_initial.py @@ -0,0 +1,45 @@ +# Generated by Django 2.2.9 on 2020-02-21 15:20 + +import ctrack.register.models +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('organisations', '0004_auto_20200220_1634'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('caf', '0002_auto_20200220_1434'), + ] + + operations = [ + migrations.CreateModel( + name='EngagementType', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('descriptor', models.CharField(max_length=50)), + ('enforcement_instrument', models.BooleanField(default=False)), + ('regulation_reference', models.CharField(blank=True, max_length=100)), + ('comments', models.TextField(max_length=1000)), + ], + ), + migrations.CreateModel( + name='EngagementEvent', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('date', models.DateTimeField()), + ('end_date', models.DateTimeField(blank=True)), + ('document_link', models.URLField(max_length=1000)), + ('response_date_requested', models.DateField()), + ('response_received', models.DateField()), + ('participants', models.ManyToManyField(to='organisations.Person')), + ('related_caf', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='caf.CAF')), + ('type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='register.EngagementType')), + ('user', models.ForeignKey(on_delete=models.SET(ctrack.register.models.EngagementEvent.get_sentinel_user), to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/ctrack/register/migrations/0002_auto_20200221_1527.py b/ctrack/register/migrations/0002_auto_20200221_1527.py new file mode 100644 index 0000000..ad82341 --- /dev/null +++ b/ctrack/register/migrations/0002_auto_20200221_1527.py @@ -0,0 +1,49 @@ +# Generated by Django 2.2.9 on 2020-02-21 15:27 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('register', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='engagementevent', + name='document_link', + field=models.URLField(blank=True, max_length=1000, null=True), + ), + migrations.AlterField( + model_name='engagementevent', + name='end_date', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AlterField( + model_name='engagementevent', + name='related_caf', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='caf.CAF'), + ), + migrations.AlterField( + model_name='engagementevent', + name='response_date_requested', + field=models.DateField(blank=True, null=True), + ), + migrations.AlterField( + model_name='engagementevent', + name='response_received', + field=models.DateField(blank=True, null=True), + ), + migrations.AlterField( + model_name='engagementtype', + name='comments', + field=models.TextField(blank=True, max_length=1000, null=True), + ), + migrations.AlterField( + model_name='engagementtype', + name='regulation_reference', + field=models.CharField(blank=True, max_length=100, null=True), + ), + ] diff --git a/ctrack/register/migrations/0003_engagementevent_short_description.py b/ctrack/register/migrations/0003_engagementevent_short_description.py new file mode 100644 index 0000000..dc976f9 --- /dev/null +++ b/ctrack/register/migrations/0003_engagementevent_short_description.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.9 on 2020-02-21 15:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('register', '0002_auto_20200221_1527'), + ] + + operations = [ + migrations.AddField( + model_name='engagementevent', + name='short_description', + field=models.CharField(default='NA', help_text='Short description of the event', max_length=50), + preserve_default=False, + ), + ] diff --git a/ctrack/register/models.py b/ctrack/register/models.py index 0b4331b..60733c5 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -1,3 +1,54 @@ -# from django.db import models +from django.contrib.auth import get_user_model +from django.db import models -# Create your models here. +from ctrack.caf.models import CAF +from ctrack.organisations.models import Person + + +class EngagementType(models.Model): + """ + Examples here are Phone, Email, Letter, Site visit, Meeting, Audit, Inspection, etc. + Also official instruments such as designation letters, Information Notices, etc. + """ + + descriptor = models.CharField(max_length=50, blank=False) + enforcement_instrument = models.BooleanField(default=False) + regulation_reference = models.CharField(max_length=100, blank=True, null=True) + comments = models.TextField(max_length=1000, blank=True, null=True) + + def __str__(self): + return self.descriptor + + +class EngagementEvent(models.Model): + """ + Involves multiple people, such as a meeting, phone call, etc. + """ + + def get_sentinel_user(): + """ + We need this so that we can ensure models.SET() is applied with a callable + to handle when Users are deleted from the system, preventing the EngagementEvent + objects related to them being deleted also. + """ + return get_user_model().objects.get_or_create(username="DELETED USER")[0] + + type = models.ForeignKey(EngagementType, on_delete=models.CASCADE) + short_description = models.CharField( + max_length=50, help_text="Short description of the event" + ) + participants = models.ManyToManyField(Person) + user = models.ForeignKey(get_user_model(), on_delete=models.SET(get_sentinel_user)) + date = models.DateTimeField() + end_date = models.DateTimeField(blank=True, null=True) + document_link = models.URLField(max_length=1000, blank=True, null=True) + response_date_requested = models.DateField(blank=True, null=True) + response_received = models.DateField(blank=True, null=True) + related_caf = models.ForeignKey( + CAF, blank=True, on_delete=models.CASCADE, null=True + ) + + def __str__(self): + d = self.date.date() + iso_format_date = d.isoformat() + return f"{iso_format_date} | {self.type.descriptor} | {self.short_description}" |