Skip to content
Snippets Groups Projects
Commit 92794616 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

handle changes to writeLog client function and clean up display name handling...

handle changes to writeLog client function and clean up display name handling for tagging of event logs
parent 1fdc1f69
No related branches found
No related tags found
No related merge requests found
from django.http import HttpResponse, HttpResponseNotFound from django.http import HttpResponse, HttpResponseNotFound
from django.http import HttpResponseForbidden, HttpResponseServerError from django.http import HttpResponseForbidden, HttpResponseServerError
from django.http.request import QueryDict
from django.urls import reverse as django_reverse from django.urls import reverse as django_reverse
from django.conf import settings from django.conf import settings
...@@ -776,12 +777,15 @@ class EventLogList(APIView): ...@@ -776,12 +777,15 @@ class EventLogList(APIView):
@event_and_auth_required @event_and_auth_required
def post(self, request, event): def post(self, request, event):
message = request.data.get('message') message = request.data.get('message')
tagnames = request.data.get('tagname', None) # Handle requests encoded as multipart/form or regular JSONs
# Convert tagnames from comma separated list. if isinstance(request.data, QueryDict):
if tagnames: # request.data is a MultiValueDict
tagnames = tagnames.split(',') tagnames = request.data.getlist('tagname', [])
displayNames = request.data.getlist('displayName', [])
else: else:
tagnames = [] # request.data is a normal dict
tagnames = request.data.get('tagname', [])
displayNames = request.data.get('displayName', [])
try: try:
uploadedFile = request.data['upload'] uploadedFile = request.data['upload']
...@@ -827,12 +831,22 @@ class EventLogList(APIView): ...@@ -827,12 +831,22 @@ class EventLogList(APIView):
if settings.EXTERNAL_ACCESS_TAGNAME not in tagnames: if settings.EXTERNAL_ACCESS_TAGNAME not in tagnames:
tagnames.append(settings.EXTERNAL_ACCESS_TAGNAME) tagnames.append(settings.EXTERNAL_ACCESS_TAGNAME)
# Check how to handle displayNames
if len(displayNames) == len(tagnames):
use_display_names = True
else:
use_display_names = False
request.data['displayName'] = ''
tw_dict = {} tw_dict = {}
if tagnames and len(tagnames): if tagnames and len(tagnames):
for tagname in tagnames: for i,tagname in enumerate(tagnames):
n = logentry.N n = logentry.N
# Yeah... this is really bad and doesn't work as expected.
# Creates any new tags all with the same displayName. # Modify request data to include display name for this tag
if use_display_names:
request.data['displayName'] = displayNames[i]
tmp = EventLogTagDetail() tmp = EventLogTagDetail()
retval = tmp.put(request, event.graceid(), n, tagname) retval = tmp.put(request, event.graceid(), n, tagname)
# XXX This seems like a bizarre way of getting an error message out. # XXX This seems like a bizarre way of getting an error message out.
...@@ -847,7 +861,6 @@ class EventLogList(APIView): ...@@ -847,7 +861,6 @@ class EventLogList(APIView):
if 'tagWarning' in tw_dict.keys(): if 'tagWarning' in tw_dict.keys():
response['tagWarning'] = tw_dict['tagWarning'] response['tagWarning'] = tw_dict['tagWarning']
# Issue alert. # Issue alert.
description = "LOG: " description = "LOG: "
fname = "" fname = ""
...@@ -1221,11 +1234,10 @@ class EventLogTagDetail(APIView): ...@@ -1221,11 +1234,10 @@ class EventLogTagDetail(APIView):
return HttpResponseForbidden(msg) return HttpResponseForbidden(msg)
# Look for the tag. If it doesn't already exist, create it. # Look for the tag. If it doesn't already exist, create it.
try: tag, created = Tag.objects.get_or_create(name=tagname)
tag = Tag.objects.filter(name=tagname)[0] displayName = request.data.get('displayName')
except: if created:
displayName = request.data.get('displayName') tag.displayName = displayName
tag = Tag(name=tagname, displayName=displayName)
tag.save() tag.save()
# Now add the log message to this tag. # Now add the log message to this tag.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment