Coverage for app/models/event.py: 84%
74 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-09-13 18:43 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-09-13 18:43 +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 multipleOfferingId = IntegerField(null=True)
23 seriesId = IntegerField(null=True)
24 isRepeating = BooleanField(default=False)
25 contactEmail = CharField(null=True)
26 contactName = CharField(null=True)
27 program = ForeignKeyField(Program)
28 isCanceled = BooleanField(default=False)
29 deletionDate = DateTimeField(null=True)
30 deletedBy = TextField(null=True)
32 _spCache = "Empty"
34 def __str__(self):
35 return f"{self.id}: {self.description}"
37 @property
38 def isDeleted(self):
39 return self.deletionDate is not None
41 @property
42 def noProgram(self):
43 return not self.program_id
45 @property
46 def isPastStart(self):
47 return datetime.now() >= datetime.combine(self.startDate, self.timeStart)
49 @property
50 def isPastEnd(self):
51 return datetime.now() >= datetime.combine(self.endDate, self.timeEnd)
53 @property
54 def isRecurring(self):
55 return bool(self.recurringId)
57 @property
58 def isFirstRepeatingEvent(self):
59 firstRepeatingEvent = Event.select().where(Event.seriesId==self.seriesId).order_by(Event.id).get()
60 return firstRepeatingEvent.id == self.id
62 @property
63 def isFirstRecurringEvent(self):
64 firstRecurringEvent = Event.select().where(Event.recurringId==self.recurringId).order_by(Event.id).get()
65 return firstRecurringEvent.id == self.id
67 @property
68 def isMultipleOffering(self):
69 return bool(self.multipleOfferingId)
71 @property
72 def relativeTime(self):
73 relativeTime = datetime.combine(self.startDate, self.timeStart) - datetime.now()
75 secondsFromNow = relativeTime.seconds
76 minutesFromNow = secondsFromNow // 60
77 hoursFromNow = minutesFromNow // 60
78 daysFromNow = relativeTime.days
79 if self.isPastStart:
80 return ""
81 elif (daysFromNow):
82 return f"{daysFromNow} day" + ("s" if daysFromNow > 1 else "")
83 elif hoursFromNow:
84 return f"{hoursFromNow} hour" + ("s" if hoursFromNow > 1 else "")
85 elif minutesFromNow:
86 return f"{minutesFromNow} minute" + ("s" if minutesFromNow > 1 else "")
87 else:
88 return f"happening now"