Coverage for app/logic/landingPage.py: 94%

31 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-10-24 20:53 +0000

1import os 

2from flask import g 

3from app.models.programManager import ProgramManager 

4from app.models.program import Program 

5from app.models.user import User 

6 

7 

8def getManagerProgramDict(user): 

9 

10 managerRows = (ProgramManager.select(ProgramManager, User, Program) 

11 .join(User) 

12 .switch(ProgramManager) 

13 .join(Program)) 

14 programs = Program.select().order_by(Program.programName) 

15 if not (user.isAdmin or user.isBonnerScholar): 

16 programs = programs.where(Program.isBonnerScholars == False) 

17 managerRows = managerRows.where(ProgramManager.program.isBonnerScholars == False) 

18 managerProgramDict = {} 

19 

20 for program in programs: 

21 managerProgramDict[program] = {"managers": "", "image": os.path.join('static', 'images/logos/celts_symbol.png')} 

22 with os.scandir("./app/static/images/landingPage") as it: 

23 for entry in it: 

24 if entry.name.split('.')[0] == f'{program.programName}': 

25 managerProgramDict[program]["image"] = os.path.join('static', f'images/landingPage/{entry.name}') 

26 break 

27 for row in managerRows: 

28 if managerProgramDict[row.program]["managers"] == "": 

29 managerProgramDict[row.program]["managers"] = f'{row.user.firstName} {row.user.lastName}' 

30 else: 

31 managerProgramDict[row.program]["managers"] = f'{managerProgramDict[row.program]["managers"]}, {row.user.firstName} {row.user.lastName}' 

32 return managerProgramDict 

33 

34def getActiveEventTab(programID): 

35 program = Program.get_by_id(programID) 

36 if program.isBonnerScholars: 

37 return "bonnerScholarsEvents" 

38 elif program.isStudentLed: 

39 return "studentLedEvents" 

40 else: 

41 return "otherEvents"