From f19ff6b22fcd1dce2ea71bb677d8b896e9459216 Mon Sep 17 00:00:00 2001 From: Branson Stephens <branson.stephens@ligo.org> Date: Thu, 2 Oct 2014 09:01:23 -0500 Subject: [PATCH] Changes to api and views for REST interface --- gracedb/api.py | 25 +++++++++++++------------ gracedb/views.py | 7 ++----- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/gracedb/api.py b/gracedb/api.py index 8616c3923..c5fb9a74d 100644 --- a/gracedb/api.py +++ b/gracedb/api.py @@ -7,6 +7,7 @@ from django.core.urlresolvers import reverse as django_reverse from django.conf import settings from django.utils.http import urlquote from django.utils import dateformat +from django.db import IntegrityError import json @@ -984,23 +985,22 @@ class EventLogDetail(APIView): #================================================================== -# EMBBEventLog +# EMBBEventLog (EEL) # FIXME -# Janky serialization +# Eel serializer. def embbEventLogToDict(eel, request=None): uri = None - file_uri = None if request: uri = reverse("embbeventlog-detail", args=[eel.event.graceid(), eel.N], request=request) return { - "comment" : eel.comment, - "created" : eel.created, - "issuer" : eel.issuer.username, "self" : uri, - "file" : file_uri, + "created" : eel.created, + "submitter" : eel.submitter.username, + "facility" : eel.facility.name, + "comment" : eel.comment, } class EMBBEventLogList(APIView): @@ -1047,13 +1047,14 @@ class EMBBEventLogList(APIView): # Now create the EEL try: eel = create_eel(request.DATA, event, request.user) - # XXX Need to handle multiple exception types here. + except ValueError, e: + return Response("str(e)", status=status.HTTP_400_BAD_REQUEST) + except IntegrityError, e: + return Response("Failed to save EMBB entry: %s" % str(e), + status=status.HTTP_503_SERVICE_UNAVAILABLE) except Exception, e: return Response("Problem creating EEL: %s" % str(e), - status=status.HTTP_400_BAD_REQUEST) -# Since this is likely due to race conditions, we will return 503 -# return Response("Failed to save log entry: %s" % str(e), -# status=status.HTTP_503_SERVICE_UNAVAILABLE) + status=status.HTTP_500_INTERNAL_SERVER_ERROR) rv = embbEventLogToDict(eel, request=request) response = Response(rv, status=status.HTTP_201_CREATED) diff --git a/gracedb/views.py b/gracedb/views.py index e386eac18..1a0eb356c 100644 --- a/gracedb/views.py +++ b/gracedb/views.py @@ -1373,17 +1373,14 @@ def embblogentry(request, graceid, num=None): eel = create_eel(request.POST, event, request.user) except ValueError, e: return HttpResponseBadRequest(str(e)) -# except RaceConditions, e: -# return HttpResponseInternalServerError(str(e)) - except Exception: - pass + except Exception, e: + return HttpResponseServerError(str(e)) else: try: eel = event.eventlog_set.filter(N=num)[0] except Exception: raise Http404 - if not request.is_ajax(): return HttpResponseRedirect(reverse(view, args=[graceid])) -- GitLab