From 7119da4d4d09eb3254fd4a8c754b84e7ace8f577 Mon Sep 17 00:00:00 2001
From: Tanner Prestegard <tanner.prestegard@ligo.org>
Date: Wed, 9 Jan 2019 12:37:43 -0600
Subject: [PATCH] Create data directories for HardwareInjections

Some additional code cleanup, as well.
---
 ...al_source_and_destination_channels_null.py |  25 ++++
 gracedb/events/models.py                      |   4 +-
 gracedb/events/view_logic.py                  |  31 ++---
 .../gracedb/event_detail_injection.html       | 120 +++++++++---------
 4 files changed, 99 insertions(+), 81 deletions(-)
 create mode 100644 gracedb/events/migrations/0030_siminspiral_source_and_destination_channels_null.py

diff --git a/gracedb/events/migrations/0030_siminspiral_source_and_destination_channels_null.py b/gracedb/events/migrations/0030_siminspiral_source_and_destination_channels_null.py
new file mode 100644
index 000000000..62ed71d30
--- /dev/null
+++ b/gracedb/events/migrations/0030_siminspiral_source_and_destination_channels_null.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-01-09 17:43
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('events', '0029_create_bbh_search'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='siminspiralevent',
+            name='destination_channel',
+            field=models.CharField(blank=True, default=b'', max_length=50, null=True),
+        ),
+        migrations.AlterField(
+            model_name='siminspiralevent',
+            name='source_channel',
+            field=models.CharField(blank=True, default=b'', max_length=50, null=True),
+        ),
+    ]
diff --git a/gracedb/events/models.py b/gracedb/events/models.py
index b52b75d68..c8391b8e7 100644
--- a/gracedb/events/models.py
+++ b/gracedb/events/models.py
@@ -843,8 +843,8 @@ class SimInspiralEvent(Event):
     eff_dist_t           = models.FloatField(null=True)
     eff_dist_v           = models.FloatField(null=True)
     # Additional desired attributes that are not in the SimInspiral table
-    source_channel       = models.CharField(max_length=50, blank=True, default="")
-    destination_channel  = models.CharField(max_length=50, blank=True, default="")
+    source_channel       = models.CharField(max_length=50, blank=True, default="", null=True)
+    destination_channel  = models.CharField(max_length=50, blank=True, default="", null=True)
 
     @classmethod
     def field_names(cls):
diff --git a/gracedb/events/view_logic.py b/gracedb/events/view_logic.py
index 03022c384..3822d9c5e 100644
--- a/gracedb/events/view_logic.py
+++ b/gracedb/events/view_logic.py
@@ -78,7 +78,8 @@ def _createEventFromForm(request, form):
         if pipeline.name in ['HardwareInjection',]:
             event.source_channel = request.POST.get('source_channel', None)
             event.destination_channel = request.POST.get('destination_channel', None)
-            event.instruments = request.POST.get('instrument', None)
+            event.instruments = request.POST.get('instrument',
+                request.POST.get('instruments', None))
 
         #  ARGH.  We don't get a graceid until we save,
         #  but we don't know in advance if we can actually
@@ -99,31 +100,23 @@ def _createEventFromForm(request, form):
         event.refresh_perms()
 
         # Create data directory/directories
-        #    Save uploaded file.
-        # Write the event data file to disk. 
-
-        # But there are way too many hardware injections to save them to disk
+        eventDir = event.datadir
+        os.makedirs(eventDir)
 
+        # Write the event data file to disk.
         f = request.FILES['eventFile']
-        if pipeline.name not in ['HardwareInjection',]:
-            eventDir = event.datadir
-            os.makedirs( eventDir )
-            uploadDestination = os.path.join(eventDir, f.name)
-            fdest = VersionedFile(uploadDestination, 'w')
-            for chunk in f.chunks():
-                fdest.write(chunk)
-            fdest.close()
-            file_contents = None
-        else:
-            uploadDestination = None
-            file_contents = f.read()
-        # Create WIKI page
+        uploadDestination = os.path.join(eventDir, f.name)
+        fdest = VersionedFile(uploadDestination, 'w')
+        for chunk in f.chunks():
+            fdest.write(chunk)
+        fdest.close()
+        file_contents = None
 
         # Extract Info from uploaded data
         # Temp (ha!) hack to deal with
         # out of band data from Omega to LUMIN.
         try:
-            temp_data_loc, translator_warnings  = handle_uploaded_data(event, uploadDestination, 
+            temp_data_loc, translator_warnings = handle_uploaded_data(event, uploadDestination, 
                 file_contents = file_contents)
             warnings += translator_warnings
 
diff --git a/gracedb/templates/gracedb/event_detail_injection.html b/gracedb/templates/gracedb/event_detail_injection.html
index fd3d6f2f0..c03adec74 100644
--- a/gracedb/templates/gracedb/event_detail_injection.html
+++ b/gracedb/templates/gracedb/event_detail_injection.html
@@ -12,73 +12,73 @@
 <!-- there are 59 total attributes. Let's split into two tables. -->
 
 <div style="display:table-cell;float:left;width:50%;">
-<table> 
-    <tr> <th> Source Channel </th> <td> {{object.source_channel}} </td> </tr>
-    <tr> <th> Destination Channel </th> <td> {{object.destination_channel}} </td> </tr> 
-    <tr> <th> mass1 </th> <td> {{object.mass1|floatformat:"-4"}} </td> </tr>
-    <tr> <th> mass2 </th> <td> {{object.mass2|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> eta </th> <td> {{object.eta|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> mchirp </th> <td> {{object.mchirp|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> amp_order </th> <td> {{object.amp_order|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> coa_phase </th> <td> {{object.coa_phase|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> spin1x </th> <td> {{object.spin1x|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> spin1y </th> <td> {{object.spin1y|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> spin1z </th> <td> {{object.spin1z|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> spin2x </th> <td> {{object.spin2x|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> spin2y </th> <td> {{object.spin2y|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> spin2z </th> <td> {{object.spin2z|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> geocent_end_time </th> <td> {{object.geocent_end_time}} </td> </tr> 
-    <tr> <th> geocent_end_time_ns </th> <td> {{object.geocent_end_time_ns}} </td> </tr> 
-    <tr> <th> end_time_gmst </th> <td> {{object.end_time_gmst}} </td> </tr> 
-    <tr> <th> f_lower </th> <td> {{object.f_lower|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> f_final </th> <td> {{object.f_final|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> distance </th> <td> {{object.distance|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> latitude </th> <td> {{object.latitude|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> longitude </th> <td> {{object.longitude|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> polarization </th> <td> {{object.polarization|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> inclination </th> <td> {{object.inclination|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> theta0 </th> <td> {{object.theta0|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> phi0 </th> <td> {{object.phi0|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> waveform </th> <td> {{object.waveform}} </td> </tr> 
-    <tr> <th> numrel_mode_min </th> <td> {{object.numrel_mode_min}} </td> </tr> 
-    <tr> <th> numrel_mode_max </th> <td> {{object.numrel_mode_max}} </td> </tr> 
+<table>
+    <tr> <th> Source Channel </th> <td> {% if object.source_channel != None %} {{ object.source_channel }} {% endif %} </td> </tr>
+    <tr> <th> Destination Channel </th> <td> {% if object.destination_channel != None %} {{ object.destination_channel }} {% endif %} </td> </tr>
+    <tr> <th> mass1 </th> <td> {% if object.mass1 != None %} {{ object.mass1|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> mass2 </th> <td> {% if object.mass2 != None %} {{ object.mass2|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> eta </th> <td> {% if object.eta != None %} {{ object.eta|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> mchirp </th> <td> {% if object.mchirp != None %} {{ object.mchirp|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> amp_order </th> <td> {% if object.amp_order != None %} {{ object.amp_order|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> coa_phase </th> <td> {% if object.coa_phase != None %} {{ object.coa_phase|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> spin1x </th> <td> {% if object.spin1x != None %} {{ object.spin1x|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> spin1y </th> <td> {% if object.spin1y != None %} {{ object.spin1y|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> spin1z </th> <td> {% if object.spin1z != None %} {{ object.spin1z|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> spin2x </th> <td> {% if object.spin2x != None %} {{ object.spin2x|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> spin2y </th> <td> {% if object.spin2y != None %} {{ object.spin2y|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> spin2z </th> <td> {% if object.spin2z != None %} {{ object.spin2z|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> geocent_end_time </th> <td> {% if object.geocent_end_time != None %} {{ object.geocent_end_time }} {% endif %} </td> </tr>
+    <tr> <th> geocent_end_time_ns </th> <td> {% if object.geocent_end_time_ns != None %} {{ object.geocent_end_time_ns }} {% endif %} </td> </tr>
+    <tr> <th> end_time_gmst </th> <td> {% if object.end_time_gmst != None %} {{ object.end_time_gmst }} {% endif %} </td> </tr>
+    <tr> <th> f_lower </th> <td> {% if object.f_lower != None %} {{ object.f_lower|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> f_final </th> <td> {% if object.f_final != None %} {{ object.f_final|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> distance </th> <td> {% if object.distance != None %} {{ object.distance|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> latitude </th> <td> {% if object.latitude != None %} {{ object.latitude|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> longitude </th> <td> {% if object.longitude != None %} {{ object.longitude|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> polarization </th> <td> {% if object.polarization != None %} {{ object.polarization|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> inclination </th> <td> {% if object.inclination != None %} {{ object.inclination|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> theta0 </th> <td> {% if object.theta0 != None %} {{ object.theta0|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> phi0 </th> <td> {% if object.phi0 != None %} {{ object.phi0|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> waveform </th> <td> {% if object.waveform != None %} {{ object.waveform }} {% endif %} </td> </tr>
+    <tr> <th> numrel_mode_min </th> <td> {% if object.numrel_mode_min != None %} {{ object.numrel_mode_min }} {% endif %} </td> </tr>
+    <tr> <th> numrel_mode_max </th> <td> {% if object.numrel_mode_max != None %} {{ object.numrel_mode_max }} {% endif %} </td> </tr>
 </table>
 </div>
 
 <div style="display:table-cell;float:right;width:50%">
 
 <table>
-    <tr> <th> numrel_data </th> <td> {{object.numrel_data}} </td> </tr> 
-    <tr> <th> source </th> <td> {{object.source}} </td> </tr> 
-    <tr> <th> taper </th> <td> {{object.taper}} </td> </tr> 
-    <tr> <th> bandpass </th> <td> {{object.bandpass}} </td> </tr> 
-    <tr> <th> alpha </th> <td> {{object.alpha|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> beta </th> <td> {{object.beta|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> psi0 </th> <td> {{object.psi0|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> psi3 </th> <td> {{object.psi3|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> alpha1 </th> <td> {{object.alpha1|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> alpha2 </th> <td> {{object.alpha2|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> alpha3 </th> <td> {{object.alpha3|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> alpha4 </th> <td> {{object.alpha4|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> alpha5 </th> <td> {{object.alpha5|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> alpha6 </th> <td> {{object.alpha6|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> g_end_time </th> <td> {{object.g_end_time}} </td> </tr> 
-    <tr> <th> g_end_time_ns </th> <td> {{object.g_end_time_ns}} </td> </tr> 
-    <tr> <th> h_end_time </th> <td> {{object.h_end_time}} </td> </tr> 
-    <tr> <th> h_end_time_ns </th> <td> {{object.h_end_time_ns}} </td> </tr> 
-    <tr> <th> l_end_time </th> <td> {{object.l_end_time}} </td> </tr> 
-    <tr> <th> l_end_time_ns </th> <td> {{object.l_end_time_ns}} </td> </tr> 
-    <tr> <th> t_end_time </th> <td> {{object.t_end_time}} </td> </tr> 
-    <tr> <th> t_end_time_ns </th> <td> {{object.t_end_time_ns}} </td> </tr> 
-    <tr> <th> v_end_time </th> <td> {{object.v_end_time}} </td> </tr> 
-    <tr> <th> v_end_time_ns </th> <td> {{object.v_end_time_ns}} </td> </tr> 
-    <tr> <th> eff_dist_g </th> <td> {{object.eff_dist_g|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> eff_dist_h </th> <td> {{object.eff_dist_h|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> eff_dist_l </th> <td> {{object.eff_dist_l|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> eff_dist_t </th> <td> {{object.eff_dist_t|floatformat:"-4"}} </td> </tr> 
-    <tr> <th> eff_dist_v </th> <td> {{object.eff_dist_v|floatformat:"-4"}} </td> </tr> 
+    <tr> <th> numrel_data </th> <td> {% if object.numrel_data != None %} {{ object.numrel_data }} {% endif %} </td> </tr>
+    <tr> <th> source </th> <td> {% if object.source != None %} {{ object.source }} {% endif %} </td> </tr>
+    <tr> <th> taper </th> <td> {% if object.taper != None %} {{ object.taper }} {% endif %} </td> </tr>
+    <tr> <th> bandpass </th> <td> {% if object.bandpass != None %} {{ object.bandpass }} {% endif %} </td> </tr>
+    <tr> <th> alpha </th> <td> {% if object.alpha != None %} {{ object.alpha|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> beta </th> <td> {% if object.beta != None %} {{ object.beta|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> psi0 </th> <td> {% if object.psi0 != None %} {{ object.psi0|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> psi3 </th> <td> {% if object.psi3 != None %} {{ object.psi3|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> alpha1 </th> <td> {% if object.alpha1 != None %} {{ object.alpha1|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> alpha2 </th> <td> {% if object.alpha2 != None %} {{ object.alpha2|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> alpha3 </th> <td> {% if object.alpha3 != None %} {{ object.alpha3|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> alpha4 </th> <td> {% if object.alpha4 != None %} {{ object.alpha4|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> alpha5 </th> <td> {% if object.alpha5 != None %} {{ object.alpha5|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> alpha6 </th> <td> {% if object.alpha6 != None %} {{ object.alpha6|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> g_end_time </th> <td> {% if object.g_end_time != None %} {{ object.g_end_time }} {% endif %} </td> </tr>
+    <tr> <th> g_end_time_ns </th> <td> {% if object.g_end_time_ns != None %} {{ object.g_end_time_ns }} {% endif %} </td> </tr>
+    <tr> <th> h_end_time </th> <td> {% if object.h_end_time != None %} {{ object.h_end_time }} {% endif %} </td> </tr>
+    <tr> <th> h_end_time_ns </th> <td> {% if object.h_end_time_ns != None %} {{ object.h_end_time_ns }} {% endif %} </td> </tr>
+    <tr> <th> l_end_time </th> <td> {% if object.l_end_time != None %} {{ object.l_end_time }} {% endif %} </td> </tr>
+    <tr> <th> l_end_time_ns </th> <td> {% if object.l_end_time_ns != None %} {{ object.l_end_time_ns }} {% endif %} </td> </tr>
+    <tr> <th> t_end_time </th> <td> {% if object.t_end_time != None %} {{ object.t_end_time }} {% endif %} </td> </tr>
+    <tr> <th> t_end_time_ns </th> <td> {% if object.t_end_time_ns != None %} {{ object.t_end_time_ns }} {% endif %} </td> </tr>
+    <tr> <th> v_end_time </th> <td> {% if object.v_end_time != None %} {{ object.v_end_time }} {% endif %} </td> </tr>
+    <tr> <th> v_end_time_ns </th> <td> {% if object.v_end_time_ns != None %} {{ object.v_end_time_ns }} {% endif %} </td> </tr>
+    <tr> <th> eff_dist_g </th> <td> {% if object.eff_dist_g != None %} {{ object.eff_dist_g|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> eff_dist_h </th> <td> {% if object.eff_dist_h != None %} {{ object.eff_dist_h|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> eff_dist_l </th> <td> {% if object.eff_dist_l != None %} {{ object.eff_dist_l|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> eff_dist_t </th> <td> {% if object.eff_dist_t != None %} {{ object.eff_dist_t|floatformat:"-4" }} {% endif %} </td> </tr>
+    <tr> <th> eff_dist_v </th> <td> {% if object.eff_dist_v != None %} {{ object.eff_dist_v|floatformat:"-4" }} {% endif %} </td> </tr>
 </table>
-</div> 
+</div>
 
 </div>
 </div> <!-- container -->
-- 
GitLab