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): ...@@ -854,10 +854,17 @@ class EventSlot(APIView):
if not os.path.exists(filePath): if not os.path.exists(filePath):
return Response("No slot created because file does not exist", return Response("No slot created because file does not exist",
status=status.HTTP_404_NOT_FOUND) status=status.HTTP_404_NOT_FOUND)
# Create the slot. # Check for existence of the slot. If it exists, simply update the
slot = Slot(event=event,name=slotname,value=filename) # existing slot.
slot.save() try:
return Response("Slot created.",status=status.HTTP_201_CREATED) 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. # Delete a slot.
def delete(self, request, graceid, slotname): def delete(self, request, graceid, slotname):
......
...@@ -6,13 +6,16 @@ from ..models import Slot, EventLog ...@@ -6,13 +6,16 @@ from ..models import Slot, EventLog
register = template.Library() register = template.Library()
@register.filter("slot") @register.filter("slot")
def slot(event,slotname): def slot(event,pattern):
if event is None: if event is None:
return mark_safe("") return None
try: try:
slot = Slot.objects.filter(event=event).filter(name=slotname)[0] # This returns a list of dictionary objects, like
out = slot.value # [{'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: 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 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