From 141b99bbb75ccad7bb618e07419b48e7279e613c Mon Sep 17 00:00:00 2001
From: Branson Stephens <branson.stephens@ligo.org>
Date: Thu, 2 Oct 2014 14:42:57 -0500
Subject: [PATCH] Fixed some bugs in API/view logic for EEL submission.

---
 gracedb/api.py    | 12 +++++++-----
 gracedb/models.py |  5 +----
 gracedb/views.py  |  9 +++------
 3 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/gracedb/api.py b/gracedb/api.py
index 3ee2cb802..c8b1ad78a 100644
--- a/gracedb/api.py
+++ b/gracedb/api.py
@@ -12,6 +12,7 @@ from django.db import IntegrityError
 import json
 
 from gracedb.models import Event, Group, EventLog, Tag
+from gracedb.models import EMFacility, EMBBEventLog, EMSPECTRUM
 from gracedb.views import create_label, get_performance_info
 from gracedb.views import create_eel
 from translator import handle_uploaded_data
@@ -26,8 +27,6 @@ import shutil
 import exceptions
 import pytz
 
-import logging
-
 from utils.vfile import VersionedFile
 
 ##################################################################
@@ -987,9 +986,8 @@ class EventLogDetail(APIView):
 
 #==================================================================
 # EMBBEventLog (EEL)
-# FIXME
 
-# Eel serializer.
+# EEL serializer.
 def embbEventLogToDict(eel, request=None):
     uri = None
     if request:
@@ -1374,7 +1372,7 @@ class GracedbRoot(APIView):
         log = reverse("eventlog-list", args=["G1200"], request=request)
         log = log.replace("G1200", "{graceid}")
         embb = reverse("embbeventlog-list", args=["G1200"], request=request)
-        embb = log.replace("G1200", "{graceid}")
+        embb = embb.replace("G1200", "{graceid}")
 
         files = reverse("files", args=["G1200", "filename"], request=request)
         files = files.replace("G1200", "{graceid}")
@@ -1420,6 +1418,10 @@ class GracedbRoot(APIView):
             "templates" : templates,
             "groups" : [group.name for group in Group.objects.all()],
             "analysis-types" : dict(Event.ANALYSIS_TYPE_CHOICES),
+            "em-facilities"  : [f.shortName for f in EMFacility.objects.all()],
+            "wavebands"      : dict(EMSPECTRUM),
+            "eel-statuses"   : dict(EMBBEventLog.EEL_STATUS_CHOICES),
+            "obs-statuses"   : dict(EMBBEventLog.OBS_STATUS_CHOICES),
            })
 
 ##################################################################
diff --git a/gracedb/models.py b/gracedb/models.py
index 7c3dcacc0..c95138657 100644
--- a/gracedb/models.py
+++ b/gracedb/models.py
@@ -10,7 +10,6 @@ import datetime
 import thread
 import string
 import os
-import logging
 
 import glue
 import glue.ligolw
@@ -19,8 +18,6 @@ import glue.ligolw.table
 import glue.ligolw.lsctables
 from glue.lal import LIGOTimeGPS
 
-log = logging.getLogger('gracedb.models')
-
 # XXX ER2.utils.  utils is in project directory.  ugh.
 from utils import posixToGpsTime
 
@@ -423,7 +420,7 @@ class EMBBEventLog(models.Model):
         if not success:
             # XXX Should this be a custom exception?  That way we could catch it
             # in the views that use it and give an informative error message.
-            raise Exception("Too many attempts to save log message. Something is wrong.")
+            raise Exception("Too many attempts to save EMBB entry. Something is wrong.")
 
 class Labelling(models.Model):
     event = models.ForeignKey(Event)
diff --git a/gracedb/views.py b/gracedb/views.py
index 1a0eb356c..b983692a7 100644
--- a/gracedb/views.py
+++ b/gracedb/views.py
@@ -1327,10 +1327,7 @@ def create_eel(d, event, user):
         raise ValueError('Please specify a facility')
 
     # Assign a facility-specific footprint ID (if provided)
-    try:
-        eel.footprintID = d.get('footprintID')
-    except: 
-        eel.footprintID = None
+    eel.footprintID = d.get('footprintID', '')
 
     # Assign the EM spectrum string
     try:
@@ -1358,8 +1355,8 @@ def create_eel(d, event, user):
     except: 
         raise ValueError('Please specify an observation status.')
 
-    eel.extra_info_dict = d.get('extra_info_dict', None) 
-    eel.comment = d.get('comment', None) 
+    eel.extra_info_dict = d.get('extra_info_dict', '') 
+    eel.comment = d.get('comment', '') 
     eel.save()
 
 # A view to create embb log entries
-- 
GitLab