Coverage for app/controllers/minor/routes.py: 36%

53 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2025-04-08 19:13 +0000

1from flask import g, render_template, request, abort, flash, redirect, url_for 

2from peewee import DoesNotExist 

3 

4from app.controllers.minor import minor_bp 

5from app.models.user import User 

6from app.models.attachmentUpload import AttachmentUpload 

7from app.models.term import Term 

8from app.logic.fileHandler import FileHandler 

9from app.logic.utils import selectSurroundingTerms, getFilesFromRequest 

10from app.logic.minor import createOtherEngagementRequest, setCommunityEngagementForUser, getSummerExperience, getEngagementTotal, createSummerExperience, getProgramEngagementHistory, getCourseInformation, getCommunityEngagementByTerm, getCCEMinorProposals, createOtherEngagementRequest 

11 

12@minor_bp.route('/profile/<username>/cceMinor', methods=['GET']) 

13def viewCceMinor(username): 

14 """ 

15 Load minor management page with community engagements and summer experience 

16 """ 

17 if not (g.current_user.isAdmin): 

18 return abort(403) 

19 

20 sustainedEngagementByTerm = getCommunityEngagementByTerm(username) 

21 

22 activeTab = request.args.get("tab", "sustainedCommunityEngagements") 

23 

24 return render_template("minor/profile.html", 

25 user = User.get_by_id(username), 

26 proposalList = getCCEMinorProposals(username), 

27 sustainedEngagementByTerm = sustainedEngagementByTerm, 

28 totalSustainedEngagements = getEngagementTotal(sustainedEngagementByTerm), 

29 activeTab=activeTab) 

30 

31@minor_bp.route('/cceMinor/<username>/otherEngagement', methods=['GET', 'POST']) 

32def requestOtherEngagement(username): 

33 """ 

34 Load minor management page with community engagements and summer experience 

35 """ 

36 if not (g.current_user.isAdmin or g.current_user.username == username): 

37 return abort(403) 

38 

39 

40 # once we submit the form for creation 

41 if request.method == "POST": 

42 createdProposal = createOtherEngagementRequest(username, request.form) 

43 attachment = request.files.get("attachmentObject") 

44 if attachment: 

45 addFile = FileHandler(getFilesFromRequest(request), proposalId=createdProposal.id) 

46 addFile.saveFiles() 

47 

48 return redirect(url_for('minor.viewCceMinor', username=username)) 

49 

50 return render_template("minor/requestOtherEngagement.html", 

51 user = User.get_by_id(username), 

52 selectableTerms = selectSurroundingTerms(g.current_term), 

53 allTerms = getSummerExperience(username)) 

54 

55 

56@minor_bp.route('/cceMinor/<username>/summerExperience', methods=['GET', 'POST']) 

57def requestSummerExperience(username): 

58 """ 

59 Load minor management page with community engagements and summer experience 

60 """ 

61 if not (g.current_user.isAdmin or g.current_user.username == username): 

62 return abort(403) 

63 

64 # once we submit the form for creation 

65 if request.method == "POST": 

66 createSummerExperience(username, request.form) 

67 return redirect(url_for('minor.viewCceMinor', username=username)) 

68 

69 summerTerms = selectSurroundingTerms(g.current_term, summerOnly=True) 

70 

71 return render_template("minor/summerExperience.html", 

72 summerTerms = summerTerms, 

73 user = User.get_by_id(username), 

74 ) 

75 

76@minor_bp.route('/cceMinor/<username>/getEngagementInformation/<type>/<term>/<id>', methods=['GET']) 

77def getEngagementInformation(username, type, id, term): 

78 """ 

79 For a particular engagement activity (program or course), get the participation history or course information respectively. 

80 """ 

81 if type == "program": 

82 information = getProgramEngagementHistory(id, username, term) 

83 else: 

84 information = getCourseInformation(id) 

85 

86 return information 

87 

88@minor_bp.route('/cceMinor/<username>/modifyCommunityEngagement', methods=['PUT','DELETE']) 

89def modifyCommunityEngagement(username): 

90 """ 

91 Saving a term participation/activities for sustained community engagement 

92 """ 

93 if not g.current_user.isCeltsAdmin: 

94 abort(403) 

95 

96 action = 'add' if request.method == 'PUT' else 'remove' 

97 try: 

98 setCommunityEngagementForUser(action, request.form, g.current_user) 

99 except DoesNotExist: 

100 return "There are already 4 Sustained Community Engagement records." 

101 

102 return "" 

103