Coverage for app/models/term.py: 93%
45 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 *
2class Term(baseModel):
3 description = CharField()
4 year = IntegerField()
5 academicYear = CharField()
6 isSummer = BooleanField(default=False)
7 isCurrentTerm = BooleanField(default=False)
8 termOrder = CharField()
10 _cache = None
12 @property
13 def academicYearStartingTerm(self):
14 """
15 Saves the term that starts the academic year of the chosen term in a cache
16 to avoid doing multiple queries for the same information.
17 """
18 if self._cache is None:
19 if ("Summer" in self.description) or ("Spring" in self.description):
20 try:
21 self._cache = Term.select().where(Term.year==self.year-1, Term.description == f"Fall {self.year-1}").get()
22 except DoesNotExist:
23 self._cache = self
25 else:
26 self._cache = self
28 return self._cache
30 @property
31 def isFutureTerm(self):
32 """
33 checks to see if the term selected is a current Term.
34 If not, depending on the year and description, it determines whether it is a future term
35 """
36 if not self.isCurrentTerm:
37 currentTerm = Term.select().where(Term.isCurrentTerm == True).get()
38 if currentTerm.year < self.year:
39 return True
40 elif currentTerm.year > self.year:
41 return False
42 else:
43 if ("Fall" in currentTerm.description):
44 return False
45 elif ("Summer" in currentTerm.description) & ("Fall" in self.description):
46 return True
47 elif ("Summer" in currentTerm.description) & ("Spring" in self.description):
48 return False
49 elif ("Spring" in currentTerm.description):
50 return True
51 return False
53 @staticmethod
54 def convertDescriptionToTermOrder(description):
55 semester,year = description.split()
56 if semester == "Spring":
57 return year + "-1"
58 elif semester == "Summer" or semester == "May":
59 return year + "-2"
60 elif semester == "Fall":
61 return year + '-3'