Coverage for app/logic/term.py: 79%
43 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-25 18:59 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-25 18:59 +0000
1from flask import session, g
2from playhouse.shortcuts import model_to_dict
3from app.logic.createLogs import createActivityLog
4from app.models.term import Term
6def addNextTerm():
7 newSemesterMap = {"Spring":"Summer",
8 "Summer":"Fall",
9 "Fall":"Spring"}
10 terms = list(Term.select().order_by(Term.termOrder))
11 prevTerm = terms[-1]
12 prevSemester, prevYear = prevTerm.description.split()
14 newYear = int(prevYear) + 1 if prevSemester == "Fall" else int(prevYear)
16 newDescription = newSemesterMap[prevSemester] + " " + str(newYear)
17 newAY = prevTerm.academicYear
18 if prevSemester == "Summer": # we only change academic year when the latest term in the table is Summer
19 year1, year2 = prevTerm.academicYear.split("-")
20 newAY = year2 + "-" + str(int(year2)+1)
22 semester = newDescription.split()[0]
23 summer= "Summer" in semester
24 newTerm = Term.create(description=newDescription,
25 year=newYear,
26 academicYear=newAY,
27 isSummer= summer,
28 termOrder=Term.convertDescriptionToTermOrder(newDescription))
29 newTerm.save()
31 return newTerm
33def addPastTerm(description):
34 semester, year = description.split()
35 if 'May' in semester:
36 semester = "Summer"
37 if semester == "Fall":
38 academicYear = year + "-" + str(int(year) + 1)
39 elif semester == "Summer" or "Spring":
40 academicYear= str(int(year) - 1) + "-" + year
42 isSummer = "Summer" in semester
43 newDescription=f"{semester} {year}"
44 orderTerm = Term.convertDescriptionToTermOrder(newDescription)
46 createdOldTerm = Term.create(description= newDescription,
47 year=year,
48 academicYear=academicYear,
49 isSummer=isSummer,
50 termOrder=orderTerm)
51 createdOldTerm.save()
52 return createdOldTerm
54def changeCurrentTerm(term):
55 oldCurrentTerm = Term.get_by_id(g.current_term)
56 oldCurrentTerm.isCurrentTerm = False
57 oldCurrentTerm.save()
58 newCurrentTerm = Term.get_by_id(term)
59 newCurrentTerm.isCurrentTerm = True
60 newCurrentTerm.save()
61 session["current_term"] = model_to_dict(newCurrentTerm)
62 createActivityLog(f"Changed Current Term from {oldCurrentTerm.description} to {newCurrentTerm.description}")