More cleanup

moved login, logout and password change from website app to musicians
This commit is contained in:
Martin Bauer
2014-01-11 15:01:40 +01:00
parent 1aa97e53d3
commit 010efe137e
13 changed files with 202 additions and 163 deletions

View File

@@ -9,6 +9,11 @@ from datetime import datetime
from location_field.models import PlainLocationField
class NoNextEventException( Exception ):
def __str__(self):
return ("No event scheduled for the future")
class Event ( models.Model ):
EVENT_TYPES = (
@@ -64,11 +69,50 @@ class Event ( models.Model ):
@property
def displaydatetime(self):
if not self.displaytime == None:
return datetime.combine( self.date, self.displaytime() )
return datetime.combine( self.date, self.displaytime )
else:
return datetime.combine( self.date, datetime.min.time())
return datetime.combine( self.date, datetime.min.time() )
@staticmethod
def getNextEvent( eventType = "", includePreviousFromToday = True ):
"""Return the next event, of the given type. If type is the empty string the next event is returned
regardless of its type.
if includePreviousFromToday the nextEvent returned could also have been today with a startime < now """
if includePreviousFromToday:
if eventType == "":
nextEvents = Event.objects.filter( date__gte = datetime.now() ).order_by('date')[:1]
else:
nextEvents = Event.objects.filter( date__gte = datetime.now(), type = eventType ).order_by('date')[:1]
if len( nextEvents ) == 0:
raise NoNextEventException()
return nextEvents[0]
else:
maximalNumberOfEventsOnSameDay = 4
nextEvents = []
if eventType =="":
nextEvents = Event.objects.filter( date__gte = datetime.now() ).order_by('date')[:maximalNumberOfEventsOnSameDay]
else:
nextEvents = Event.objects.filter( date__gte = datetime.now(), type = eventType ).order_by('date')[:maximalNumberOfEventsOnSameDay]
if len(nextEvents) == 0:
raise NoNextEventException()
i = 0
nextEvent = nextEvents[0]
# nextEvent is not necessarily events[0] since events[0] may have been previously today
while nextEvent.displaydatetime < datetime.now():
if len(nextEvents ) <= i:
raise NoNextEventException()
else:
i += 1
nextEvent = nextEvents[i]
return nextEvent
class EventParticipation( models.Model ):
OPTIONS = ( ('?' , _('?' )),