def displayStemIIIPblPlanner(): printLogEntry("Running displayStemIIIPblPlanner()") pbls = Pbls.query.order_by( Pbls.schoolYear.desc(), Pbls.quarter.desc(), Pbls.pblName ) pblEvents = ( PblEvents.query.join(Pbls) .filter(Pbls.quarter >= 0) .order_by( Pbls.quarter.desc(), PblEvents.eventDate, PblEvents.startTime, Pbls.pblName, ) ) quarterOptions = getQuarterChoices() currentQuarter = getCurrentQuarter() if request.method == "GET" and request.args.get("selectedQuarter"): quarter = request.args.get("selectedQuarter") print("selectedQuarter =", quarter) quarter = int(quarter) elif request.method == "POST": quarter = request.form["selectedQuarter"] print("selectedQuarter =", quarter) quarter = int(quarter) else: quarter = getCurrentQuarter() # Get list of kickoff and final PBL events for current year and selected quarter academicYear = getCurrentAcademicYear() pblKickoffEvents = ( PblEvents.query.join(Pbls) .filter( PblEvents.eventCategory == "Kickoff", Pbls.academicYear == academicYear, Pbls.quarter == quarter, ) .order_by(PblEvents.eventDate, PblEvents.startTime, Pbls.pblName,) ) pblFinalEvents = ( PblEvents.query.join(Pbls) .filter( PblEvents.eventCategory == "Final", Pbls.academicYear == academicYear, Pbls.quarter == quarter, ) .order_by(PblEvents.eventDate, PblEvents.startTime, Pbls.pblName,) ) return render_template( "pblplanner.html", title="STEM III PBL Planner", pbls=pbls, pblEvents=pblEvents, quarterOptions=quarterOptions, displayQuarter=quarter, pblKickoffEvents=pblKickoffEvents, pblFinalEvents=pblFinalEvents, )
def download_PblFieldTripInfo(): printLogEntry("Running download_PblEvents()") if request.method == "POST": quarter = request.form["selectedQuarter"] print("selectedQuarter =", quarter) quarter = int(quarter) else: quarter = getCurrentQuarter() return downloadPblFieldTripInfo(quarter)
def download_PblTeamsAndEvents(): printLogEntry("Running download_PblTeamsAndEvents()") if request.method == "POST": quarter = request.form["selectedQuarter"] eventCategory = request.form["selectedEventCategory"] print("selectedQuarter =", quarter) quarter = int(quarter) else: quarter = getCurrentQuarter() eventCategory = "Kickoff" return downloadPblTeamsAndEventDetails(quarter, eventCategory)
def download_PblReports(): printLogEntry("Running download_PblReports()") quarterOptions = getQuarterChoices() currentQuarter = getCurrentQuarter() eventCategoryChoices = getPblEventCategoryChoices() return render_template( "pblreports.html", title="STEM III PBL Reports", quarterOptions=quarterOptions, displayQuarter=currentQuarter, eventCategoryChoices=eventCategoryChoices, )
def displayStemIIITeams(): printLogEntry("Running displayStemIIITeams()") # Create list of students to include for PBL teams students = db.session.query( Student.firstName, Student.lastName, Student.chattStateANumber ).filter(Student.yearOfGraduation == getClassYearOfGraduation("Juniors")) # Create PblTeam for each student for each quarter className = "STEM III" academicYear = getCurrentAcademicYear() quarters = [1, 2, 3, 4] for student in students: for quarter in quarters: # Check whether PblTeam exists for student log = PblTeams.query.filter( PblTeams.className == className, PblTeams.academicYear == academicYear, PblTeams.quarter == quarter, PblTeams.chattStateANumber == student.chattStateANumber, ).first() # Skip the record if the student is already in the PblTeams table if log: pass # Add a new record if the student is not already in the PblTeams table else: schoolYear, semester = getSchoolYearAndSemester(academicYear, quarter) pblTeam = PblTeams( className=className, academicYear=academicYear, schoolYear=schoolYear, semester=semester, quarter=quarter, pblNumber=quarter, pblTeamNumber=0, chattStateANumber=student.chattStateANumber, pbl_id=None, ) db.session.add(pblTeam) db.session.commit() print( "Adding new PBL Team for", student.firstName, student.lastName, student.chattStateANumber, ) # Check request.method for different scenarios: # Default: GET with no parameters will display PBL team based on computed current quarter # POST with request.form handles case when user changes quarter using dropdown menu # GET with selectedQuarter handles case when redirected from saving team in order to stay # on previous page # The team event list uses eventCategory so it must be set to a default value if not included if request.method == "GET" and request.args.get("selectedQuarter"): quarter = request.args.get("selectedQuarter") print("selectedQuarter =", quarter) quarter = int(quarter) if request.args.get("selectedEventCategory"): eventCategory = request.args.get("selectedEventCategory") print("selectedEventCategory =", eventCategory) else: eventCategory = "Kickoff" elif request.method == "POST": print(request.form) selectedQuarter = request.form["selectedQuarter"] print("selectedQuarter =", selectedQuarter) quarter = int(selectedQuarter) try: if request.form["selectedEventCategory"]: eventCategory = request.form["selectedEventCategory"] except: eventCategory = "Kickoff" else: quarter = getCurrentQuarter() eventCategory = "Kickoff" pblTeams = ( PblTeams.query.outerjoin(Pbls) .join(Student) .filter( PblTeams.className == className, PblTeams.academicYear == academicYear, PblTeams.quarter == quarter, ) .order_by(Pbls.pblName, PblTeams.pblTeamNumber, Student.lastName) .all() ) # Create set of numbered teams to assign students teamNumbers = [] for i in range(1, 31, 1): teamNumbers.append(f"{i}") # Create tuple of pblOptions and set default choice to None pblOptions = list(getPblOptionsTuple(academicYear, quarter)) pblOptions.insert(0, ("", "Choose PBL...")) pblOptions = tuple(pblOptions) # Create choices for PBL Team Communications Center pblEmailRecipientChoices = getPblEmailRecipientChoices( academicYear, quarter, className ) pblCommunicationsActions = getPblEmailTemplates() print(pblOptions) quarterOptions = getQuarterChoices() eventCategoryChoices = getPblEventCategoryChoices() # Get list of PBL students and event info to display for PBL Team Event List pblTeamsAndEvents = ( db.session.query(PblTeams, PblEvents) .select_from(PblTeams) .outerjoin(Pbls) .outerjoin(Pbls.PblEvents) .join(Student) .filter(Pbls.quarter == quarter, PblEvents.eventCategory == eventCategory) .order_by( Pbls.quarter, PblEvents.eventDate, PblEvents.startTime, Pbls.pblName, PblTeams.pblTeamNumber, Student.lastName, ) ) return render_template( "pblteams.html", title="STEM III Team Manager", students=students, teamNumbers=teamNumbers, pblOptions=pblOptions, pblTeams=pblTeams, quarterOptions=quarterOptions, displayQuarter=quarter, pblEmailRecipientChoices=pblEmailRecipientChoices, pblEmailTemplates=pblCommunicationsActions, eventCategoryChoices=eventCategoryChoices, displayEventCategory=eventCategory, pblTeamsAndEvents=pblTeamsAndEvents, )