Coverage for app/models/event.py: 85%

68 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-09-03 17:48 +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 multipleOfferingId = IntegerField(null=True) 

23 contactEmail = CharField(null=True) 

24 contactName = CharField(null=True) 

25 program = ForeignKeyField(Program) 

26 isCanceled = BooleanField(default=False) 

27 deletionDate = DateTimeField(null=True) 

28 deletedBy = TextField(null=True) 

29 

30 _spCache = "Empty" 

31 

32 def __str__(self): 

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

34 

35 @property 

36 def isDeleted(self): 

37 return self.deletionDate is not None 

38 

39 @property 

40 def noProgram(self): 

41 return not self.program_id 

42 

43 @property 

44 def isPastStart(self): 

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

46 

47 @property 

48 def isPastEnd(self): 

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

50 

51 @property 

52 def isRecurring(self): 

53 return bool(self.recurringId) 

54 

55 @property 

56 def isFirstRecurringEvent(self): 

57 firstRecurringEvent = Event.select().where(Event.recurringId==self.recurringId).order_by(Event.id).get() 

58 return firstRecurringEvent.id == self.id 

59 

60 @property 

61 def isMultipleOffering(self): 

62 return bool(self.multipleOfferingId) 

63 

64 @property 

65 def relativeTime(self): 

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

67 

68 secondsFromNow = relativeTime.seconds 

69 minutesFromNow = secondsFromNow // 60 

70 hoursFromNow = minutesFromNow // 60 

71 daysFromNow = relativeTime.days 

72 if self.isPastStart: 

73 return "" 

74 elif (daysFromNow): 

75 return f"{daysFromNow} day" + ("s" if daysFromNow > 1 else "") 

76 elif hoursFromNow: 

77 return f"{hoursFromNow} hour" + ("s" if hoursFromNow > 1 else "") 

78 elif minutesFromNow: 

79 return f"{minutesFromNow} minute" + ("s" if minutesFromNow > 1 else "") 

80 else: 

81 return f"happening now" 

82 

83