Coverage for app/models/event.py: 87%
63 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-11-19 23:53 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-11-19 23:53 +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 isEngagement = BooleanField(default=False)
18 isAllVolunteerTraining = BooleanField(default=False)
19 rsvpLimit = IntegerField(null=True)
20 startDate = DateField()
21 endDate = DateField(null=True)
22 seriesId = IntegerField(null=True)
23 isRepeating = BooleanField(default=False)
24 contactEmail = CharField(null=True)
25 contactName = CharField(null=True)
26 program = ForeignKeyField(Program)
27 isCanceled = BooleanField(default=False)
28 deletionDate = DateTimeField(null=True)
29 deletedBy = TextField(null=True)
31 _spCache = "Empty"
33 def __str__(self):
34 return f"{self.id}: {self.description}"
36 @property
37 def isDeleted(self):
38 return self.deletionDate is not None
40 @property
41 def noProgram(self):
42 return not self.program_id
44 @property
45 def isPastStart(self):
46 return datetime.now() >= datetime.combine(self.startDate, self.timeStart)
48 @property
49 def isPastEnd(self):
50 return datetime.now() >= datetime.combine(self.endDate, self.timeEnd)
52 @property
53 def isFirstRepeatingEvent(self):
54 firstRepeatingEvent = Event.select().where(Event.seriesId==self.seriesId).order_by(Event.id).get()
55 return firstRepeatingEvent.id == self.id
57 @property
58 def relativeTime(self):
59 relativeTime = datetime.combine(self.startDate, self.timeStart) - datetime.now()
61 secondsFromNow = relativeTime.seconds
62 minutesFromNow = secondsFromNow // 60
63 hoursFromNow = minutesFromNow // 60
64 daysFromNow = relativeTime.days
65 if self.isPastStart:
66 return ""
67 elif (daysFromNow):
68 return f"{daysFromNow} day" + ("s" if daysFromNow > 1 else "")
69 elif hoursFromNow:
70 return f"{hoursFromNow} hour" + ("s" if hoursFromNow > 1 else "")
71 elif minutesFromNow:
72 return f"{minutesFromNow} minute" + ("s" if minutesFromNow > 1 else "")
73 else:
74 return f"happening now"