Coverage for app/logic/graduationManagement.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.10.2, created at 2026-01-23 18:51 +0000

1import xlsxwriter 

2from app import app 

3from peewee import JOIN 

4 

5from app.models.user import User 

6from app.models.bonnerCohort import BonnerCohort 

7from app.logic.minor import getMinorProgress 

8 

9def getGraduationManagementUsers(): 

10 """ 

11 Function to fetch all senior students along with their CCE Minor Progress and Bonner Status  

12 """ 

13 

14 eligibleUsers = (User.select(User.username, User.hasGraduated, User.rawClassLevel, User.firstName, User.lastName, BonnerCohort.year) 

15 .join(BonnerCohort, JOIN.LEFT_OUTER, on=(BonnerCohort.user == User.username)) 

16 .where((User.rawClassLevel == 'Senior') | (User.rawClassLevel == "Graduating") | (User.hasGraduated == True) | (User.rawClassLevel == "Alumni"))) 

17 

18 cceStudents = set([user["username"] for user in getMinorProgress()]) 

19 

20 graduationManagementUsers = [] 

21 for user in eligibleUsers: 

22 userDict = user.__dict__ 

23 graduationManagementUsers.append({ 

24 "user": user, 

25 "cohort": userDict['bonnercohort'].year if 'bonnercohort' in userDict else None, 

26 "minorProgress": user.username in cceStudents}) 

27 

28 return graduationManagementUsers 

29 

30def setGraduatedStatus(username, status): 

31 """ 

32 Update a student's graduation status. 

33 """ 

34 gradStudent = User.get(User.username == username) 

35 

36 # it is necessary we cast this to an int instead of a bool because the 

37 # status is passed as a string and if we cast it to a bool it will always be True 

38 

39 status = int(status) 

40 

41 if status == 1: 

42 # Mark as alumni 

43 gradStudent.hasGraduated = True 

44 gradStudent.rawClassLevel = "Graduating" 

45 else: 

46 # Revert to currently enrolled senior 

47 gradStudent.hasGraduated = False 

48 gradStudent.rawClassLevel = "Senior" 

49 

50 gradStudent.save() 

51 

52