diff --git a/gracedb/api.py b/gracedb/api.py index 496d62fd53726a9d507d41cf0e03963035b5f93e..146c721a813dab58c4163c086f24ecd9e61a1fa5 100644 --- a/gracedb/api.py +++ b/gracedb/api.py @@ -854,10 +854,17 @@ class EventSlot(APIView): if not os.path.exists(filePath): return Response("No slot created because file does not exist", status=status.HTTP_404_NOT_FOUND) - # Create the slot. - slot = Slot(event=event,name=slotname,value=filename) - slot.save() - return Response("Slot created.",status=status.HTTP_201_CREATED) + # Check for existence of the slot. If it exists, simply update the + # existing slot. + try: + slot = Slot.objects.filter(event=event).filter(name=slotname)[0] + slot.value = filename + slot.save() + except: + # Create the slot. + slot = Slot(event=event,name=slotname,value=filename) + slot.save() + return Response("Slot created or updated.",status=status.HTTP_201_CREATED) # Delete a slot. def delete(self, request, graceid, slotname): diff --git a/gracedb/templatetags/slot.py b/gracedb/templatetags/slot.py index fff26f11fd6e5ae918006c7d32e561a213a7f9b7..97c9524bd1357475883206066d5a3d68a5bc08f3 100644 --- a/gracedb/templatetags/slot.py +++ b/gracedb/templatetags/slot.py @@ -6,13 +6,16 @@ from ..models import Slot, EventLog register = template.Library() @register.filter("slot") -def slot(event,slotname): +def slot(event,pattern): if event is None: - return mark_safe("") + return None try: - slot = Slot.objects.filter(event=event).filter(name=slotname)[0] - out = slot.value + # This returns a list of dictionary objects, like + # [{'event': event, 'name': 'skymap', 'value':'skymap.png'}, ... ] + # XXX doesn't the template need the full path? + return Slot.objects.filter(event=event).filter(name__regex=pattern).values() except: + # Either there is no such slot or something went wrong. + # In either case, we want the template to just ignore it. return None - return mark_safe(out)