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

1from app.models import * 

2from app.models.term import Term 

3from app.models.program import Program 

4from datetime import datetime 

5 

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) 

28 

29 _spCache = "Empty" 

30 

31 def __str__(self): 

32 return f"{self.id}: {self.description}" 

33 

34 @property 

35 def isDeleted(self): 

36 return self.deletionDate is not None 

37 

38 @property 

39 def noProgram(self): 

40 return not self.program_id 

41 

42 @property 

43 def isPastStart(self): 

44 return datetime.now() >= datetime.combine(self.startDate, self.timeStart) 

45 

46 @property 

47 def isPastEnd(self): 

48 return datetime.now() >= datetime.combine(self.endDate, self.timeEnd) 

49 

50 @property 

51 def isRecurring(self): 

52 return bool(self.recurringId) 

53 

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 

58 

59 @property 

60 def relativeTime(self): 

61 relativeTime = datetime.combine(self.startDate, self.timeStart) - datetime.now() 

62 

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" 

77 

78