Coverage for app/models/event.py: 86%
64 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-07-31 16:31 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-07-31 16:31 +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)
26 deletionDate = DateTimeField(null=True)
27 deletedBy = TextField(null=True)
29 _spCache = "Empty"
31 def __str__(self):
32 return f"{self.id}: {self.description}"
34 @property
35 def isDeleted(self):
36 return self.deletionDate is not None
38 @property
39 def noProgram(self):
40 return not self.program_id
42 @property
43 def isPastStart(self):
44 return datetime.now() >= datetime.combine(self.startDate, self.timeStart)
46 @property
47 def isPastEnd(self):
48 return datetime.now() >= datetime.combine(self.endDate, self.timeEnd)
50 @property
51 def isRecurring(self):
52 return bool(self.recurringId)
54 @property
55 def isFirstRecurringEvent(self):
56 firstRecurringEvent = Event.select().where(Event.recurringId==self.recurringId).order_by(Event.id).get()
57 return firstRecurringEvent.id == self.id
59 @property
60 def relativeTime(self):
61 relativeTime = datetime.combine(self.startDate, self.timeStart) - datetime.now()
63 secondsFromNow = relativeTime.seconds
64 minutesFromNow = secondsFromNow // 60
65 hoursFromNow = minutesFromNow // 60
66 daysFromNow = relativeTime.days
67 if self.isPastStart:
68 return ""
69 elif (daysFromNow):
70 return f"{daysFromNow} day" + ("s" if daysFromNow > 1 else "")
71 elif hoursFromNow:
72 return f"{hoursFromNow} hour" + ("s" if hoursFromNow > 1 else "")
73 elif minutesFromNow:
74 return f"{minutesFromNow} minute" + ("s" if minutesFromNow > 1 else "")
75 else:
76 return f"happening now"