Coverage for app/controllers/minor/routes.py: 38%
58 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-09-18 19:56 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-09-18 19:56 +0000
1from flask import g, render_template, request, abort, flash, redirect, url_for
2from peewee import DoesNotExist
4from app.controllers.minor import minor_bp
5from app.models.user import User
6from app.models.term import Term
7from app.models.attachmentUpload import AttachmentUpload
9from app.logic.fileHandler import FileHandler
10from app.logic.utils import selectSurroundingTerms, getFilesFromRequest
11from app.logic.minor import getProgramEngagementHistory, getCourseInformation, getCommunityEngagementByTerm, removeSummerExperience
12from app.logic.minor import saveOtherEngagementRequest, setCommunityEngagementForUser, saveSummerExperience, getSummerTerms, getSummerExperience, getEngagementTotal
14@minor_bp.route('/profile/<username>/cceMinor', methods=['GET'])
15def viewCceMinor(username):
16 """
17 Load minor management page with community engagements and summer experience
18 """
19 if not (g.current_user.isAdmin):
20 return abort(403)
22 sustainedEngagementByTerm = getCommunityEngagementByTerm(username)
23 selectedSummerTerm, summerExperience = getSummerExperience(username)
25 return render_template("minor/profile.html",
26 user = User.get_by_id(username),
27 sustainedEngagementByTerm = sustainedEngagementByTerm,
28 summerExperience = summerExperience if summerExperience else "",
29 selectedSummerTerm = selectedSummerTerm,
30 totalSustainedEngagements = getEngagementTotal(sustainedEngagementByTerm),
31 summerTerms = getSummerTerms())
33@minor_bp.route('/cceMinor/<username>/getEngagementInformation/<type>/<term>/<id>', methods=['GET'])
34def getEngagementInformation(username, type, id, term):
35 """
36 For a particular engagement activity (program or course), get the participation history or course information respectively.
37 """
38 if type == "program":
39 information = getProgramEngagementHistory(id, username, term)
40 else:
41 information = getCourseInformation(id)
43 return information
45@minor_bp.route('/cceMinor/<username>/modifyCommunityEngagement', methods=['PUT','DELETE'])
46def modifyCommunityEngagement(username):
47 """
48 Saving a term participation/activities for sustained community engagement
49 """
50 if not g.current_user.isCeltsAdmin:
51 abort(403)
53 action = 'add' if request.method == 'PUT' else 'remove'
54 try:
55 setCommunityEngagementForUser(action, request.form, g.current_user)
56 except DoesNotExist:
57 return "There are already 4 Sustained Community Engagement records."
59 return ""
61@minor_bp.route('/cceMinor/<username>/requestOtherCommunityEngagement', methods=['GET', 'POST'])
62def requestOtherEngagement(username):
63 """
64 Load the "request other" form and submit it.
65 """
66 user = User.get_by_id(username)
67 terms = selectSurroundingTerms(g.current_term)
70 if request.method == 'POST':
71 filename = None
72 attachment = request.files.get("attachmentObject")
73 if attachment:
74 addFile = FileHandler(getFilesFromRequest(request))
75 addFile.saveFiles()
76 filename = attachment.filename
77 formData = request.form.copy()
78 formData["filename"] = filename
79 saveOtherEngagementRequest(formData)
80 flash("Other community engagement request submitted.", "success")
81 return redirect(url_for("minor.viewCceMinor", username=user))
84 return render_template("/minor/requestOtherEngagement.html",
85 user=user,
86 terms=terms)
88@minor_bp.route('/cceMinor/<username>/addSummerExperience', methods=['POST'])
89def addSummerExperience(username):
90 saveSummerExperience(username, request.form, g.current_user)
92 return ""
94@minor_bp.route('/cceMinor/<username>/deleteSummerExperience', methods=['POST'])
95def deleteSummerExperience(username):
96 removeSummerExperience(username)
98 return ""