Skip to content
Snippets Groups Projects
Commit e9572e23 authored by Branson Stephens's avatar Branson Stephens
Browse files

fixed slot duplication. template filter now returns list of slot dicts.'

parent a1663303
No related branches found
No related tags found
No related merge requests found
......@@ -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):
......
......@@ -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)
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