def saveTeams(): printLogEntry("Running saveTeams()") teamListjson = request.form["teamList"] teamList = json.loads(teamListjson) quarter = int(request.form["quarter"]) className = "STEM III" academicYear = getCurrentAcademicYear() schoolYear, semester = getSchoolYearAndSemester(academicYear, quarter) pblNumber = quarter for team, teamInfo in teamList.items(): print(team, teamInfo["teamMemberList"], teamInfo["pblChoice"]) # Get the team number from team name (e.g. extract '1' from 'Team 1') pblTeamNumber = int(team.split()[1].strip()) # Set the pblChoice to None if student not in team or if team's pblChoice is not set if pblTeamNumber == 0: pblChoice = None elif teamInfo["pblChoice"] == "": pblChoice = None else: pblChoice = int(teamInfo["pblChoice"]) for chattStateANumber in teamInfo["teamMemberList"]: # Update database with PblTeam info # Get PblTeam log for student if it exists log = PblTeams.query.filter( PblTeams.className == className, PblTeams.academicYear == academicYear, PblTeams.quarter == quarter, PblTeams.chattStateANumber == chattStateANumber, ).first() # Update the record if the student is already in the PblTeams table if log: log.pblTeamNumber = pblTeamNumber log.pbl_id = pblChoice # Add a new record if the student is not already in the PblTeams table else: pblTeam = PblTeams( className=className, academicYear=academicYear, schoolYear=schoolYear, semester=semester, quarter=quarter, pblNumber=pblNumber, pblTeamNumber=pblTeamNumber, chattStateANumber=chattStateANumber, pbl_id=pblChoice, ) db.session.add(pblTeam) db.session.commit() flash("Teams have been saved!", "success") return redirect( url_for("pblPlanner_bp.displayStemIIITeams", selectedQuarter=quarter) )
def edit_Pbl(log_id): printLogEntry("Running edit_Pbl()") pblEditorFormDetails = pblEditorForm() pblEditorFormDetails.className.choices = [("STEM III", "STEM III")] pblEditorFormDetails.schoolYear.choices = getSchoolYearChoices() pblEditorFormDetails.academicYear.choices = getAcademicYearChoices() pblEditorFormDetails.semester.choices = getSemesterChoices() quarterChoices = list(getQuarterChoices()) quarterChoices.insert(0, (0, "TBD")) quarterChoices = tuple(quarterChoices) pblEditorFormDetails.quarter.choices = quarterChoices # pblEditorFormDetails.pblName.choices = getPblOptionsTuple(2) log = Pbls.query.get_or_404(log_id) LogDetails = f"{(log_id)} {log.pblName}" printLogEntry("Running edit_Pbl(" + LogDetails + ")") if "submitEditPbl" in request.form: print("request.form", request.form) if not pblEditorFormDetails.validate_on_submit(): print("Edit PBL Form errors") printFormErrors(pblEditorFormDetails) if pblEditorFormDetails.validate_on_submit(): print("submitEditPbl submitted") # Update the database with the values submitted in the form log.className = pblEditorFormDetails.className.data # Check whether the PBL academic year has changed newAcademicYear = False if log.academicYear != pblEditorFormDetails.academicYear.data: newAcademicYear = True log.academicYear = pblEditorFormDetails.academicYear.data # Check whether the PBL quarter has changed newQuarter = False if log.quarter != pblEditorFormDetails.quarter.data: newQuarter = True log.quarter = pblEditorFormDetails.quarter.data log.schoolYear, log.semester = getSchoolYearAndSemester( log.academicYear, log.quarter ) log.pblNumber = log.quarter log.pblName = pblEditorFormDetails.pblName.data log.pblSponsor = pblEditorFormDetails.pblSponsor.data log.pblSponsorPersonName = pblEditorFormDetails.pblSponsorPersonName.data log.pblSponsorPhone = pblEditorFormDetails.pblSponsorPhone.data log.pblSponsorEmail = pblEditorFormDetails.pblSponsorEmail.data log.pblComments = pblEditorFormDetails.pblComments.data # If the PBL year or quarter has been updated, check whether # the change impacts any PBL teams and remove the PBL from # impacted teams if necessary if newAcademicYear or newQuarter: impactedPblTeams = PblTeams.query.filter(PblTeams.pbl_id == log_id) for pblTeam in impactedPblTeams: pblTeam.pbl_id = None print( f"PBL year or quarter has changed. Removing PBL {log_id} from PBL Team {pblTeam.id}" ) db.session.commit() return redirect(url_for("pblPlanner_bp.displayStemIIIPblPlanner")) pblName = log.pblName print("pblName =", pblName) if log: pblEditorFormDetails.log_id.data = log.id pblEditorFormDetails.className.data = log.className pblEditorFormDetails.schoolYear.data = log.schoolYear pblEditorFormDetails.academicYear.data = log.academicYear pblEditorFormDetails.semester.data = log.semester pblEditorFormDetails.quarter.data = log.quarter pblEditorFormDetails.pblName.data = log.pblName pblEditorFormDetails.pblSponsor.data = log.pblSponsor pblEditorFormDetails.pblSponsorPersonName.data = log.pblSponsorPersonName pblEditorFormDetails.pblSponsorPhone.data = log.pblSponsorPhone pblEditorFormDetails.pblSponsorEmail.data = log.pblSponsorEmail pblEditorFormDetails.pblComments.data = log.pblComments print( "editPblDetails=", pblEditorFormDetails.log_id.data, pblEditorFormDetails.pblName.data, ) return render_template( "pbleditor.html", title="PBL Editor", pblEditorForm=pblEditorFormDetails, pblName=pblName, )
def new_Pbl(): printLogEntry("Running new_Pbl()") pblEditorFormDetails = pblEditorForm(academicYear=getCurrentAcademicYear()) pblEditorFormDetails.className.choices = [("STEM III", "STEM III")] pblEditorFormDetails.schoolYear.choices = getSchoolYearChoices() pblEditorFormDetails.academicYear.choices = getAcademicYearChoices() pblEditorFormDetails.semester.choices = getSemesterChoices() quarterChoices = list(getQuarterChoices()) quarterChoices.insert(0, (0, "TBD")) quarterChoices = tuple(quarterChoices) pblEditorFormDetails.quarter.choices = quarterChoices pblEditorFormDetails.log_id.data = 0 if "submitEditPbl" in request.form: print("request.form", request.form) if not pblEditorFormDetails.validate_on_submit(): print("Edit PBL Form errors") printFormErrors(pblEditorFormDetails) if pblEditorFormDetails.validate_on_submit(): print("submitEditPbl submitted") # Update the database with the values submitted in the form className = pblEditorFormDetails.className.data academicYear = pblEditorFormDetails.academicYear.data schoolYear = pblEditorFormDetails.schoolYear.data semester = pblEditorFormDetails.semester.data quarter = pblEditorFormDetails.quarter.data schoolYear, semester = getSchoolYearAndSemester(academicYear, quarter) pblName = pblEditorFormDetails.pblName.data pblSponsor = pblEditorFormDetails.pblSponsor.data pblSponsorPersonName = pblEditorFormDetails.pblSponsorPersonName.data pblSponsorEmail = pblEditorFormDetails.pblSponsorEmail.data pblSponsorPhone = pblEditorFormDetails.pblSponsorPhone.data pblComments = pblEditorFormDetails.pblComments.data pblLog = Pbls( className=className, schoolYear=schoolYear, academicYear=academicYear, semester=semester, quarter=quarter, pblNumber=quarter, pblName=pblName, pblSponsor=pblSponsor, pblSponsorPersonName=pblSponsorPersonName, pblSponsorEmail=pblSponsorEmail, pblSponsorPhone=pblSponsorPhone, pblComments=pblComments, ) db.session.add(pblLog) db.session.commit() # Use id for PBL record to create placeholder kickoff and final events pblEventLog = PblEvents( pbl_id=pblLog.id, eventCategory="Kickoff", confirmed=0, startTime=time(hour=9, minute=30, second=0), endTime=time(hour=10, minute=30, second=0), eventCity="Chattanooga", eventState="TN", ) db.session.add(pblEventLog) db.session.commit() pblEventLog = PblEvents( pbl_id=pblLog.id, eventCategory="Final", confirmed=0, startTime=time(hour=9, minute=30, second=0), endTime=time(hour=10, minute=30, second=0), eventCity="Chattanooga", eventState="TN", ) db.session.add(pblEventLog) db.session.commit() flash("New PBL created!", "success") return redirect(url_for("pblPlanner_bp.displayStemIIIPblPlanner")) return render_template( "pbleditor.html", title="New PBL Editor", pblEditorForm=pblEditorFormDetails, pblName=None, )
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, )