move comments out of experiments_flowcell flowcell id and into lane status
authorDiane Trout <diane@ghic.org>
Tue, 12 May 2015 19:18:47 +0000 (12:18 -0700)
committerDiane Trout <diane@ghic.org>
Tue, 12 May 2015 19:18:47 +0000 (12:18 -0700)
experiments/migrations/0003_migrate_fcid_status.py [new file with mode: 0644]
experiments/models.py

diff --git a/experiments/migrations/0003_migrate_fcid_status.py b/experiments/migrations/0003_migrate_fcid_status.py
new file mode 100644 (file)
index 0000000..3fc9ade
--- /dev/null
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+from htsworkflow.util.conversion import parse_flowcell_id
+
+
+def split_status(apps, schema_editor):
+    FlowCell = apps.get_model("experiments", "FlowCell")
+
+    statuses = {'(archived)': None,
+                '(failed)': 0,
+                '(not run)': 100,
+                '(deleted)': None}
+
+    for fc in FlowCell.objects.all():
+        fc_id, status = parse_flowcell_id(fc.flowcell_id)
+        if status is not None:
+            fc.flowcell_id = fc_id
+            new_status = statuses.get(status.strip(), None)
+            if new_status:
+                for lane in fc.lane_set:
+                    lane.status = new_status
+                    print(lane.status)
+                    lane.status.save()
+            fc.save()
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ('experiments', '0002_load_filedata'),
+    ]
+
+    operations = [
+        migrations.RunPython(split_status)
+    ]
index 7dc64c713170b5233931ddea84424bedb95b43c2..81c4440788b418e5fc5b9af612ece5984b063d7c 100644 (file)
@@ -277,7 +277,8 @@ class FlowCell(models.Model):
 
 LANE_STATUS_CODES = [(0, 'Failed'),
                      (1, 'Marginal'),
-                     (2, 'Good'), ]
+                     (2, 'Good'),
+                     (100, 'Not run')]
 LANE_STATUS_MAP = dict((int(k), v) for k, v in LANE_STATUS_CODES)
 LANE_STATUS_MAP[None] = "Unknown"