2014-01-11 15:01:40 +01:00
|
|
|
from datetime import datetime
|
2019-01-05 11:27:15 +01:00
|
|
|
from .models import Event, EventParticipation, NoNextEventException
|
2014-01-11 15:01:40 +01:00
|
|
|
from musicians.models import Musician
|
|
|
|
|
|
|
|
|
2019-01-05 11:27:15 +01:00
|
|
|
def addEventCountdownForNextEventToContext(context, username, eventType=""):
|
2014-01-11 15:01:40 +01:00
|
|
|
"""Returns an object that has to be added to the render context on the page where the countdown
|
|
|
|
should be displayed . The username is required to also supply participation information."""
|
2019-01-05 11:27:15 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
nextEvent = Event.getNextEvent(eventType, False)
|
2014-01-11 15:01:40 +01:00
|
|
|
except NoNextEventException:
|
|
|
|
return
|
2019-01-05 11:27:15 +01:00
|
|
|
|
2014-01-11 15:01:40 +01:00
|
|
|
countdown = dict()
|
|
|
|
|
2019-01-05 11:27:15 +01:00
|
|
|
if EventParticipation.isMember(username):
|
|
|
|
part = EventParticipation.objects.filter(user=username).filter(event=nextEvent)
|
2014-01-11 15:01:40 +01:00
|
|
|
countdown['participation'] = part[0].status
|
|
|
|
|
|
|
|
eventTime = nextEvent.displaydatetime
|
|
|
|
countdown['event'] = nextEvent
|
2019-01-05 11:27:15 +01:00
|
|
|
countdown['epoch'] = int((eventTime - datetime.now()).total_seconds() * 1000)
|
|
|
|
|
2014-01-11 15:01:40 +01:00
|
|
|
context["countdown"] = countdown
|
|
|
|
|
|
|
|
|
2019-01-05 11:27:15 +01:00
|
|
|
def addEventRouteForNextEventToContext(context, username, eventType=""):
|
2014-01-11 15:01:40 +01:00
|
|
|
"""Returns an object that has to be added to the render context on the page where the route
|
|
|
|
should be displayed . The starting address of the route will be the home of the specified user"""
|
2019-01-05 11:27:15 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
nextEvent = Event.getNextEvent(eventType, True)
|
2014-01-11 15:01:40 +01:00
|
|
|
except NoNextEventException:
|
|
|
|
return
|
|
|
|
|
|
|
|
routeInfo = dict()
|
|
|
|
|
|
|
|
routeInfo['event'] = nextEvent
|
|
|
|
|
2019-01-05 11:27:15 +01:00
|
|
|
musician = Musician.objects.get(user=username);
|
|
|
|
routeInfo['origin'] = musician.street + ", " + str(musician.zip_code) + " " + musician.city
|
|
|
|
|
2014-01-11 15:01:40 +01:00
|
|
|
if nextEvent.map_location:
|
|
|
|
# map_location has format "lat,longitute,zoomlevel"
|
2019-01-05 11:27:15 +01:00
|
|
|
routeInfo['destination'] = ",".join(nextEvent.map_location.split(",")[:2])
|
2014-01-11 15:01:40 +01:00
|
|
|
else:
|
|
|
|
routeInfo['destination'] = nextEvent.location
|
2019-01-05 11:27:15 +01:00
|
|
|
|
2014-01-11 15:01:40 +01:00
|
|
|
context["route"] = routeInfo
|