Coverage for app/models/event.py: 85%
59 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-07-24 12:19 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-07-24 12:19 +0000
1from app.models import *
2from app.models.term import Term
3from app.models.program import Program
4from datetime import datetime
6class Event(baseModel):
7 name = CharField()
8 term = ForeignKeyField(Term)
9 description = TextField()
10 timeStart = TimeField()
11 timeEnd = TimeField()
12 location = CharField()
13 isFoodProvided = BooleanField(default=False)
14 isTraining = BooleanField(default=False)
15 isRsvpRequired = BooleanField(default=False)
16 isService = BooleanField(default=False)
17 isAllVolunteerTraining = BooleanField(default=False)
18 rsvpLimit = IntegerField(null=True)
19 startDate = DateField()
20 endDate = DateField(null=True)
21 recurringId = IntegerField(null=True)
22 contactEmail = CharField(null=True)
23 contactName = CharField(null=True)
24 program = ForeignKeyField(Program)
25 isCanceled = BooleanField(default=False)
27 _spCache = "Empty"
29 def __str__(self):
30 return f"{self.id}: {self.description}"
32 @property
33 def noProgram(self):
34 return not self.program_id
36 @property
37 def isPastStart(self):
38 return datetime.now() >= datetime.combine(self.startDate, self.timeStart)
40 @property
41 def isPastEnd(self):
42 return datetime.now() >= datetime.combine(self.endDate, self.timeEnd)
44 @property
45 def isRecurring(self):
46 return bool(self.recurringId)
48 @property
49 def isFirstRecurringEvent(self):
50 firstRecurringEvent = Event.select().where(Event.recurringId==self.recurringId).order_by(Event.id).get()
51 return firstRecurringEvent.id == self.id
53 @property
54 def relativeTime(self):
55 relativeTime = datetime.combine(self.startDate, self.timeStart) - datetime.now()
57 secondsFromNow = relativeTime.seconds
58 minutesFromNow = secondsFromNow // 60
59 hoursFromNow = minutesFromNow // 60
60 daysFromNow = relativeTime.days
61 if self.isPastStart:
62 return ""
63 elif (daysFromNow):
64 return f"{daysFromNow} day" + ("s" if daysFromNow > 1 else "")
65 elif hoursFromNow:
66 return f"{hoursFromNow} hour" + ("s" if hoursFromNow > 1 else "")
67 elif minutesFromNow:
68 return f"{minutesFromNow} minute" + ("s" if minutesFromNow > 1 else "")
69 else:
70 return f"happening now"