From 3b7e07bc280a17b636f41ca68c22d317d957a2ca Mon Sep 17 00:00:00 2001
From: Matthew Dillon <matthewrdillon@gmail.com>
Date: Mon, 4 Dec 2017 21:21:09 -0700
Subject: [PATCH] ENH: collections - rename flaws and add notes (#41)

---
 .../migrations/0005_rename_flaws_field.py     | 20 +++++++++++++++++++
 .../migrations/0006_collection_notes.py       | 20 +++++++++++++++++++
 ccdb/collections_ccdb/models.py               |  5 +++--
 ccdb/collections_ccdb/serializers.py          |  6 +++---
 ccdb/collections_ccdb/tests/factories.py      |  3 ++-
 5 files changed, 48 insertions(+), 6 deletions(-)
 create mode 100644 ccdb/collections_ccdb/migrations/0005_rename_flaws_field.py
 create mode 100644 ccdb/collections_ccdb/migrations/0006_collection_notes.py

diff --git a/ccdb/collections_ccdb/migrations/0005_rename_flaws_field.py b/ccdb/collections_ccdb/migrations/0005_rename_flaws_field.py
new file mode 100644
index 0000000..a3d9ddd
--- /dev/null
+++ b/ccdb/collections_ccdb/migrations/0005_rename_flaws_field.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.8 on 2017-12-04 12:43
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('collections_ccdb', '0004_DATA_reset_sequences'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='collection',
+            old_name='flaw',
+            new_name='collection_flaw',
+        ),
+    ]
diff --git a/ccdb/collections_ccdb/migrations/0006_collection_notes.py b/ccdb/collections_ccdb/migrations/0006_collection_notes.py
new file mode 100644
index 0000000..15a3547
--- /dev/null
+++ b/ccdb/collections_ccdb/migrations/0006_collection_notes.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.8 on 2017-12-04 12:51
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('collections_ccdb', '0005_rename_flaws_field'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='collection',
+            name='notes',
+            field=models.TextField(blank=True),
+        ),
+    ]
diff --git a/ccdb/collections_ccdb/models.py b/ccdb/collections_ccdb/models.py
index d1b3da5..41be456 100644
--- a/ccdb/collections_ccdb/models.py
+++ b/ccdb/collections_ccdb/models.py
@@ -68,6 +68,7 @@ class Collection(models.Model):
     collection_start_time = models.TimeField(blank=True, null=True)
     collection_end_date = models.DateField(blank=True, null=True)
     collection_end_time = models.TimeField(blank=True, null=True)
+    notes = models.TextField(blank=True, null=False)
     storage_location = models.ForeignKey('locations.StorageLocation',
                                          blank=True, null=True,
                                          related_name='collections')
@@ -78,8 +79,8 @@ class Collection(models.Model):
                                 related_name='collections')
     adfg_permit = models.ForeignKey(ADFGPermit, blank=True, null=True,
                                     related_name='collections')
-    flaw = models.ForeignKey(Flaw, blank=True, null=True,
-                             related_name='collections')
+    collection_flaw = models.ForeignKey(Flaw, blank=True, null=True,
+                                        related_name='collections')
     display_name = models.CharField(max_length=255, editable=False)
 
     def save(self, *args, **kwargs):
diff --git a/ccdb/collections_ccdb/serializers.py b/ccdb/collections_ccdb/serializers.py
index de65a02..44b9a88 100644
--- a/ccdb/collections_ccdb/serializers.py
+++ b/ccdb/collections_ccdb/serializers.py
@@ -15,7 +15,7 @@ class CollectionSerializer(serializers.ModelSerializer):
             'ccdb.collections_ccdb.serializers.CollectionMethodSerializer',
         'collection_type':
             'ccdb.collections_ccdb.serializers.CollectionTypeSerializer',
-        'flaw': 'ccdb.collections_ccdb.serializers.FlawSerializer',
+        'collection_flaw': 'ccdb.collections_ccdb.serializers.FlawSerializer',
         'collection_species':
             'ccdb.species.serializers.CollectionSpeciesSerializer',
         'datasheets':
@@ -29,8 +29,8 @@ class CollectionSerializer(serializers.ModelSerializer):
                   'collection_start_date', 'collection_start_time',
                   'collection_end_date', 'collection_end_time',
                   'storage_location', 'specimen_state', 'process_type',
-                  'reagent', 'adfg_permit', 'flaw', 'display_name',
-                  'collection_species', 'datasheets')
+                  'reagent', 'adfg_permit', 'collection_flaw', 'display_name',
+                  'collection_species', 'datasheets', 'notes')
         read_only_fields = ('collection_species', 'datasheets')
 
 
diff --git a/ccdb/collections_ccdb/tests/factories.py b/ccdb/collections_ccdb/tests/factories.py
index c310c7b..7be2647 100644
--- a/ccdb/collections_ccdb/tests/factories.py
+++ b/ccdb/collections_ccdb/tests/factories.py
@@ -61,12 +61,13 @@ class CollectionFactory(DjangoModelFactory):
     collection_start_time = None
     collection_end_date = FuzzyDate(date(2015, 1, 1))
     collection_end_time = None
+    notes = FuzzyText(length=150)
     storage_location = SubFactory(StorageLocationFactory)
     specimen_state = FuzzyText(length=50)
     process_type = SubFactory(ProcessTypeFactory)
     reagent = SubFactory(ReagentFactory)
     adfg_permit = SubFactory(ADFGPermitFactory)
-    flaw = SubFactory(FlawFactory)
+    collection_flaw = SubFactory(FlawFactory)
 
 
 class DatasheetAttachmentFactory(DjangoModelFactory):