From 33b66eeae5bdd62fb884037e314cb3db10677dd8 Mon Sep 17 00:00:00 2001
From: Tanner Prestegard <tanner.prestegard@ligo.org>
Date: Wed, 16 Jan 2019 14:18:16 -0600
Subject: [PATCH] Add three new labels for hardware injections

---
 docs/user_docs/source/labels.rst              |  6 ++
 .../events/migrations/0031_hwinj_labels.py    | 59 +++++++++++++++++++
 2 files changed, 65 insertions(+)
 create mode 100644 gracedb/events/migrations/0031_hwinj_labels.py

diff --git a/docs/user_docs/source/labels.rst b/docs/user_docs/source/labels.rst
index 46a68af3c..b4b190865 100644
--- a/docs/user_docs/source/labels.rst
+++ b/docs/user_docs/source/labels.rst
@@ -51,6 +51,12 @@ Here is a table showing the currently available labels and their meanings.
 +-----------------+----------------------------------------------------------------------------------------------------------------------------------------+
 | H1OPS           | H1 operator signoff requested.                                                                                                         |
 +-----------------+----------------------------------------------------------------------------------------------------------------------------------------+
+| HWINJNO         | There were problems with the hardware injection.                                                                                       |
++-----------------+----------------------------------------------------------------------------------------------------------------------------------------+
+| HWINJOK         | A hardware injection was successfully performed.                                                                                       |
++-----------------+----------------------------------------------------------------------------------------------------------------------------------------+
+| HWINJREQ        | A hardware injection is scheduled.                                                                                                     |
++-----------------+----------------------------------------------------------------------------------------------------------------------------------------+
 | INJ             | Injection occured near this time.                                                                                                      |
 +-----------------+----------------------------------------------------------------------------------------------------------------------------------------+
 | L1NO            | L1 operator says event is not okay.                                                                                                    |
diff --git a/gracedb/events/migrations/0031_hwinj_labels.py b/gracedb/events/migrations/0031_hwinj_labels.py
new file mode 100644
index 000000000..12974169d
--- /dev/null
+++ b/gracedb/events/migrations/0031_hwinj_labels.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-01-16 20:07:23
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+# List of label names, default colors, and descriptions
+LABELS = [
+    {
+        'name': 'HWINJREQ',
+        'defaultColor': 'black',
+        'description': 'A hardware injection is scheduled.',
+    },
+    {
+        'name': 'HWINJOK',
+        'defaultColor': 'green',
+        'description': 'A hardware injection was successfully performed.',
+    },
+    {
+        'name': 'HWINJNO',
+        'defaultColor': 'red',
+        'description': 'There were problems with the hardware injection.',
+    },
+]
+
+def add_labels(apps, schema_editor):
+    Label = apps.get_model('events', 'Label')
+
+    # Create labels
+    for label_dict in LABELS:
+        l, created = Label.objects.get_or_create(name=label_dict['name'])
+        l.defaultColor = label_dict['defaultColor']
+        l.description = label_dict['description']
+        l.save()
+
+
+def remove_labels(apps, schema_editor):
+    Label = apps.get_model('events', 'Label')
+
+    # Delete labels
+    for label_dict in LABELS:
+        try:
+            l = Label.objects.get(name=label_dict['name'])
+        except Label.DoesNotExist:
+            print('Label {0} not found to be deleted, skipping.' \
+                .format(label_dict['name']))
+            break
+        l.delete()
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('events', '0030_siminspiral_source_and_destination_channels_null'),
+    ]
+
+    operations = [
+        migrations.RunPython(add_labels, remove_labels),
+    ]
-- 
GitLab