Coverage for app/models/event.py: 84%
56 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-06-18 19:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-06-18 19:54 +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 isPast(self):
38 return datetime.now() >= datetime.combine(self.startDate, self.timeStart)
40 @property
41 def isRecurring(self):
42 return bool(self.recurringId)
44 @property
45 def isFirstRecurringEvent(self):
46 firstRecurringEvent = Event.select().where(Event.recurringId==self.recurringId).order_by(Event.id).get()
47 return firstRecurringEvent.id == self.id
49 @property
50 def relativeTime(self):
51 relativeTime = datetime.combine(self.startDate, self.timeStart) - datetime.now()
53 secondsFromNow = relativeTime.seconds
54 minutesFromNow = secondsFromNow // 60
55 hoursFromNow = minutesFromNow // 60
56 daysFromNow = relativeTime.days
57 if self.isPast:
58 return ""
59 elif (daysFromNow):
60 return f"{daysFromNow} day" + ("s" if daysFromNow > 1 else "")
61 elif hoursFromNow:
62 return f"{hoursFromNow} hour" + ("s" if hoursFromNow > 1 else "")
63 elif minutesFromNow:
64 return f"{minutesFromNow} minute" + ("s" if minutesFromNow > 1 else "")
65 else:
66 return f"happening now"