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

69 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-11-22 20:53 +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 isEngagement = BooleanField(default=False) 

18 isAllVolunteerTraining = BooleanField(default=False) 

19 rsvpLimit = IntegerField(null=True) 

20 startDate = DateField() 

21 endDate = DateField(null=True) 

22 recurringId = IntegerField(null=True) 

23 multipleOfferingId = IntegerField(null=True) 

24 contactEmail = CharField(null=True) 

25 contactName = CharField(null=True) 

26 program = ForeignKeyField(Program) 

27 isCanceled = BooleanField(default=False) 

28 deletionDate = DateTimeField(null=True) 

29 deletedBy = TextField(null=True) 

30 

31 _spCache = "Empty" 

32 

33 def __str__(self): 

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

35 

36 @property 

37 def isDeleted(self): 

38 return self.deletionDate is not None 

39 

40 @property 

41 def noProgram(self): 

42 return not self.program_id 

43 

44 @property 

45 def isPastStart(self): 

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

47 

48 @property 

49 def isPastEnd(self): 

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

51 

52 @property 

53 def isRecurring(self): 

54 return bool(self.recurringId) 

55 

56 @property 

57 def isFirstRecurringEvent(self): 

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

59 return firstRecurringEvent.id == self.id 

60 

61 @property 

62 def isMultipleOffering(self): 

63 return bool(self.multipleOfferingId) 

64 

65 @property 

66 def relativeTime(self): 

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

68 

69 secondsFromNow = relativeTime.seconds 

70 minutesFromNow = secondsFromNow // 60 

71 hoursFromNow = minutesFromNow // 60 

72 daysFromNow = relativeTime.days 

73 if self.isPastStart: 

74 return "" 

75 elif (daysFromNow): 

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

77 elif hoursFromNow: 

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

79 elif minutesFromNow: 

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

81 else: 

82 return f"happening now" 

83 

84