def displayScheduleAdmin(): printLogEntry("Running displayScheduleAdmin()") uploadClassScheduleFormDetails = uploadClassScheduleForm() propagateClassAttendanceLogsFormDetails = propagateClassAttendanceLogsForm( ) propagateClassAttendanceLogsFormDetails.schoolYear.choices = getSchoolYear( ) propagateClassAttendanceLogsFormDetails.semester.choices = getSemester() deleteClassScheduleFormDetails = deleteClassScheduleForm() deleteClassScheduleFormDetails.schoolYear.choices = getSchoolYear() deleteClassScheduleFormDetails.semester.choices = getSemester() deleteClassScheduleFormDetails.yearOfGraduation.choices = getYearOfGraduation( ) downloadClassScheduleFormDetails = downloadClassScheduleForm() downloadClassScheduleFormDetails.schoolYear.choices = getSchoolYear() downloadClassScheduleFormDetails.semester.choices = getSemester() downloadClassAttendanceFormDetails = downloadClassAttendanceForm() downloadClassAttendanceFormDetails.schoolYear.choices = getSchoolYear() downloadClassAttendanceFormDetails.semester.choices = getSemester() downloadClassAttendanceFormDetails.teacherName.choices = getTeachers() addSingleClassScheduleDetails = addSingleClassSchedule() addSingleClassScheduleDetails.schoolYear.choices = getSchoolYear() addSingleClassScheduleDetails.semester.choices = getSemester() addSingleClassScheduleDetails.teacherName.choices = getTeachers() addSingleClassScheduleDetails.studentName.choices = getStudents() addSingleClassScheduleDetails.campus.choices = getCampusChoices() addSingleClassScheduleDetails.className.choices = getClassNames() addSingleClassScheduleDetails.classDays.choices = [ ("M", "M"), ("T", "T"), ("W", "W"), ("R", "R"), ("F", "F"), ] if request.method == "POST": printLogEntry("form= " + str(request.form)) if "submitUploadClassSchedule" in request.form: if uploadClassScheduleFormDetails.validate_on_submit(): printLogEntry("Upload Form Submitted") if uploadClassScheduleFormDetails.csvClassScheduleFile.data: uploadedScheduleFile = save_File( uploadClassScheduleFormDetails.csvClassScheduleFile.data, "Uploaded_Schedule_File.csv", ) uploadSchedules(uploadedScheduleFile) return redirect( url_for("scheduleAdmin_bp.displayScheduleAdmin")) printFormErrors(uploadClassScheduleFormDetails) if "submitPropagatelassAttendanceLogs" in request.form: if propagateClassAttendanceLogsFormDetails.validate_on_submit(): printLogEntry("Propagate Form Submitted") schoolYear = int( propagateClassAttendanceLogsFormDetails.schoolYear.data) semester = propagateClassAttendanceLogsFormDetails.semester.data startDate = propagateClassAttendanceLogsFormDetails.startDate.data endDate = propagateClassAttendanceLogsFormDetails.endDate.data print( "schoolYear=", schoolYear, "semester=", semester, "startDate=", startDate, "endDate=", endDate, ) propagateClassSchedule(startDate, endDate, schoolYear, semester) return redirect(url_for("scheduleAdmin_bp.displayScheduleAdmin")) printFormErrors(propagateClassAttendanceLogsFormDetails) if "submitDeleteClassScheduleForm" in request.form: if deleteClassScheduleFormDetails.validate_on_submit(): if (deleteClassScheduleFormDetails.confirmDeleteClassSchedule.data == "DELETE"): printLogEntry("Delete Class Schedule Form Submitted") schoolYear = deleteClassScheduleFormDetails.schoolYear.data semester = deleteClassScheduleFormDetails.semester.data yearOfGraduation = deleteClassScheduleFormDetails.yearOfGraduation.data print( "SchoolYear=", schoolYear, " Semester=", semester, yearOfGraduation, ) deleteClassSchedule(schoolYear, semester, yearOfGraduation) deleteClassScheduleFormDetails.confirmDeleteClassSchedule.data = "" # deleteClassScheduleFormDetails.process() return redirect( url_for("scheduleAdmin_bp.displayScheduleAdmin")) else: deleteClassScheduleFormDetails.confirmDeleteClassSchedule.data = "" printLogEntry("Type DELETE in the text box to confirm delete") if "submitAddSingleClassSchedule" in request.form: if addSingleClassScheduleDetails.validate_on_submit(): printLogEntry("Add Single Class Schedule submitted") schoolYear = addSingleClassScheduleDetails.schoolYear.data semester = addSingleClassScheduleDetails.semester.data chattStateANumber = addSingleClassScheduleDetails.studentName.data teacherLastName = addSingleClassScheduleDetails.teacherName.data className = addSingleClassScheduleDetails.className.data classDaysList = addSingleClassScheduleDetails.classDays.data classDays = "" for classDay in classDaysList: classDays = classDays + classDay startTime = addSingleClassScheduleDetails.startTime.data endTime = addSingleClassScheduleDetails.endTime.data online = addSingleClassScheduleDetails.online.data indStudy = addSingleClassScheduleDetails.indStudy.data comment = addSingleClassScheduleDetails.comment.data googleCalendarEventID = ( addSingleClassScheduleDetails.googleCalendarEventID.data) campus = "STEM School" staffID = None print( schoolYear, semester, chattStateANumber, teacherLastName, className, classDays, startTime, endTime, online, indStudy, comment, googleCalendarEventID, ) addClassSchedule( schoolYear, semester, chattStateANumber, campus, className, teacherLastName, staffID, online, indStudy, classDays, startTime, endTime, comment, googleCalendarEventID, ) return redirect(url_for("scheduleAdmin_bp.displayScheduleAdmin")) if "submitDownloadClassScheduleForm" in request.form: if downloadClassScheduleFormDetails.validate_on_submit(): schoolYear = downloadClassScheduleFormDetails.schoolYear.data semester = downloadClassScheduleFormDetails.semester.data printLogEntry("Download Class Schedule Form Submitted") print( "SchoolYear=", schoolYear, " Semester=", semester, ) return downloadClassSchedule(schoolYear, semester) if "submitDownloadClassAttendanceForm" in request.form: if downloadClassAttendanceFormDetails.validate_on_submit(): schoolYear = downloadClassAttendanceFormDetails.schoolYear.data semester = downloadClassAttendanceFormDetails.semester.data teacherName = downloadClassAttendanceFormDetails.teacherName.data startDate = downloadClassAttendanceFormDetails.startDate.data endDate = downloadClassAttendanceFormDetails.endDate.data printLogEntry("Download Class Attendance Form Submitted") print( "SchoolYear=", schoolYear, " Semester=", semester, " teacherName=", teacherName, " startDate=", startDate, " endDate=", endDate, ) return downloadClassAttendanceLog(schoolYear, semester, teacherName, startDate, endDate) return render_template( "scheduleadmin.html", title="Schedule Admin", propagateClassAttendanceLogsForm= propagateClassAttendanceLogsFormDetails, uploadClassScheduleForm=uploadClassScheduleFormDetails, deleteClassScheduleForm=deleteClassScheduleFormDetails, downloadClassScheduleForm=downloadClassScheduleFormDetails, downloadClassAttendanceForm=downloadClassAttendanceFormDetails, addSingleClassSchedule=addSingleClassScheduleDetails, )
def displayP2MTAdmin(): printLogEntry("Running displayP2MTAdmin()") addStudentFormDetails = addStudentForm() selectStudentToEditFormDetails = selectStudentToEditForm() selectStudentToEditFormDetails.studentName.choices = getStudentsById() downloadStudentListFormDetails = downloadStudentListForm() uploadStudentListFormDetails = uploadStudentListForm() deleteStudentFormDetails = deleteStudentForm() deleteStudentFormDetails.studentName.choices = getStudents() selectParentsToEditFormDetails = selectParentsToEditForm() selectParentsToEditFormDetails.studentName.choices = getStudents() downloadParentsListFormDetails = downloadParentsListForm() uploadParentsListFormDetails = uploadParentsListForm() addStaffFormDetails = addStaffForm() selectStaffToEditFormDetails = selectStaffToEditForm() selectStaffToEditFormDetails.staffName.choices = getStaffFromFacultyAndStaff( ) downloadStaffListFormDetails = downloadStaffListForm() uploadStaffListFormDetails = uploadStaffListForm() deleteStaffFormDetails = deleteStaffForm() deleteStaffFormDetails.staffName.choices = getStaffFromFacultyAndStaff() # Retrieve staff info for display (except for system account) staffInfo = FacultyAndStaff.query.filter( FacultyAndStaff.lastName != "System").order_by( FacultyAndStaff.lastName.asc()) if request.method == "POST": printLogEntry("form= " + str(request.form)) if "submitAddStudent" in request.form: if addStudentFormDetails.validate_on_submit(): printLogEntry("Add Student submitted") firstName = addStudentFormDetails.firstName.data lastName = addStudentFormDetails.lastName.data chattStateANumber = addStudentFormDetails.chattStateANumber.data email = addStudentFormDetails.email.data yearOfGraduation = int(addStudentFormDetails.yearOfGraduation.data) house = addStudentFormDetails.house.data googleCalendarId = addStudentFormDetails.googleCalendarId.data addStudentToDatabase( chattStateANumber, firstName, lastName, email, house, yearOfGraduation, googleCalendarId, ) return redirect(url_for("p2mtAdmin_bp.displayP2MTAdmin")) printFormErrors(addStudentFormDetails) if "submitStudentToEdit" in request.form: if selectStudentToEditFormDetails.validate_on_submit: printLogEntry("Student to Edit Form Submitted") student_id = int(selectStudentToEditFormDetails.studentName.data) print("student_id = ", student_id) return redirect( url_for("p2mtAdmin_bp.updateStudent", student_id=student_id)) printFormErrors(selectStudentToEditFormDetails) if "submitDownloadStudentListForm" in request.form: if downloadStudentListFormDetails.validate_on_submit(): printLogEntry("Download Student List Form Submitted") return downloadStudentList() if "submitUploadStudentList" in request.form: if uploadStudentListFormDetails.validate_on_submit(): printLogEntry("Upload Student List Form Submitted") if uploadStudentListFormDetails.csvStudentListFile.data: uploadedStudentListFile = save_File( uploadStudentListFormDetails.csvStudentListFile.data, "Uploaded_StudentList_File.csv", ) uploadStudentList(uploadedStudentListFile) return redirect(url_for("p2mtAdmin_bp.displayP2MTAdmin")) printFormErrors(uploadStudentListFormDetails) if "submitDeleteStudent" in request.form: if deleteStudentFormDetails.validate_on_submit(): if deleteStudentFormDetails.confirmDeleteStudent.data == "DELETE": printLogEntry("Delete Student Form Submitted") # studentName returns chattStateANumber as its value chattStateANumber = deleteStudentFormDetails.studentName.data print("chattStateANumber =", chattStateANumber) deleteStudent(chattStateANumber) deleteStudentFormDetails.confirmDeleteStudent.data = "" # deleteClassScheduleFormDetails.process() return redirect(url_for("p2mtAdmin_bp.displayP2MTAdmin")) else: deleteStudentFormDetails.confirmDeleteStudent.data = "" printLogEntry("Type DELETE in the text box to confirm delete") printFormErrors(deleteStudentFormDetails) if "submitParentsToEdit" in request.form: if selectParentsToEditFormDetails.validate_on_submit: printLogEntry("Parents to Edit Form Submitted") chattStateANumber = selectParentsToEditFormDetails.studentName.data print("chattStateANumber = ", chattStateANumber) return redirect( url_for("p2mtAdmin_bp.updateParents", chattStateANumber=chattStateANumber)) printFormErrors(selectParentsToEditFormDetails) if "submitDownloadParentsListForm" in request.form: if downloadParentsListFormDetails.validate_on_submit(): printLogEntry("Download Parent List Form Submitted") return downloadParentsList() if "submitUploadParentsList" in request.form: if uploadParentsListFormDetails.validate_on_submit(): printLogEntry("Upload Parents List Form Submitted") if uploadParentsListFormDetails.csvParentsListFile.data: uploadedParentsListFile = save_File( uploadParentsListFormDetails.csvParentsListFile.data, "Uploaded_ParentsList_File.csv", ) uploadParentsList(uploadedParentsListFile) return redirect(url_for("p2mtAdmin_bp.displayP2MTAdmin")) printFormErrors(uploadParentsListFormDetails) if "submitAddStaff" in request.form: if addStaffFormDetails.validate_on_submit(): printLogEntry("Add Staff submitted") firstName = addStaffFormDetails.firstName.data lastName = addStaffFormDetails.lastName.data position = addStaffFormDetails.position.data email = addStaffFormDetails.email.data phoneNumber = addStaffFormDetails.phoneNumber.data chattStateANumber = addStaffFormDetails.chattStateANumber.data myersBriggs = addStaffFormDetails.myersBriggs.data house = addStaffFormDetails.house.data houseGrade = addStaffFormDetails.houseGrade.data twitterAccount = addStaffFormDetails.twitterAccount.data addStaffToDatabase( firstName, lastName, position, email, phoneNumber, chattStateANumber, myersBriggs, house, houseGrade, twitterAccount, ) return redirect(url_for("p2mtAdmin_bp.displayP2MTAdmin")) printFormErrors(addStaffFormDetails) if "submitDownloadStaffListForm" in request.form: if downloadStaffListFormDetails.validate_on_submit(): printLogEntry("Download Staff List Form Submitted") return downloadStaffList() if "submitStaffToEdit" in request.form: if selectStaffToEditFormDetails.validate_on_submit: printLogEntry("Staff to Edit Form Submitted") staff_id = int(selectStaffToEditFormDetails.staffName.data) print("staff_id = ", staff_id) return redirect( url_for("p2mtAdmin_bp.updateStaff", staff_id=staff_id)) printFormErrors(selectStaffToEditFormDetails) if "submitUploadStaffList" in request.form: if uploadStaffListFormDetails.validate_on_submit(): printLogEntry("Upload Staff List Form Submitted") if uploadStaffListFormDetails.csvStaffListFile.data: uploadedStaffListFile = save_File( uploadStaffListFormDetails.csvStaffListFile.data, "Uploaded_StaffList_File.csv", ) uploadStaffList(uploadedStaffListFile) return redirect(url_for("p2mtAdmin_bp.displayP2MTAdmin")) printFormErrors(uploadStaffListFormDetails) if "submitDeleteStaff" in request.form: if deleteStaffFormDetails.validate_on_submit(): if deleteStaffFormDetails.confirmDeleteStaff.data == "DELETE": printLogEntry("Delete Staff Form Submitted") # staffname returns log id as its value log_id = int(deleteStaffFormDetails.staffName.data) print("log_id =", log_id) deleteStaff(log_id) deleteStaffFormDetails.confirmDeleteStaff.data = "" # deleteClassScheduleFormDetails.process() return redirect(url_for("p2mtAdmin_bp.displayP2MTAdmin")) else: deleteStaffFormDetails.confirmDeleteStaff.data = "" printLogEntry("Type DELETE in the text box to confirm delete") printFormErrors(deleteStaffFormDetails) return render_template( "p2mtadmin.html", title="P2MT Admin", staffInfo=staffInfo, addStudentForm=addStudentFormDetails, selectStudentToEditForm=selectStudentToEditFormDetails, downloadStudentListForm=downloadStudentListFormDetails, uploadStudentListForm=uploadStudentListFormDetails, deleteStudentForm=deleteStudentFormDetails, selectParentsToEditForm=selectParentsToEditFormDetails, downloadParentsListForm=downloadParentsListFormDetails, uploadParentsListForm=uploadParentsListFormDetails, addStaffForm=addStaffFormDetails, selectStaffToEditForm=selectStaffToEditFormDetails, downloadStaffListForm=downloadStaffListFormDetails, uploadStaffListForm=uploadStaffListFormDetails, deleteStaffForm=deleteStaffFormDetails, )
def edit_PblEvent(log_id): pblEventEditorFormDetails = pblEventEditorForm() pblEventEditorFormDetails.eventCategory.choices = getPblEventCategoryChoices() log = PblEvents.query.get_or_404(log_id) LogDetails = f"{(log_id)} {log.Pbls.pblName} {log.eventCategory}" event_quarter = log.Pbls.quarter printLogEntry("Running edit_PblEvent(" + LogDetails + ")") if "submitEditPblEvent" in request.form: print("request.form", request.form) if not pblEventEditorFormDetails.validate_on_submit(): print("Edit PBL Event Form errors") printFormErrors(pblEventEditorFormDetails) if pblEventEditorFormDetails.validate_on_submit(): print("submitEditPblEvent submitted") # Update the database with the values submitted in the form log.eventCategory = pblEventEditorFormDetails.eventCategory.data log.confirmed = pblEventEditorFormDetails.confirmed.data log.eventDate = pblEventEditorFormDetails.eventDate.data # Format time values from string objects to time objects startTime = datetime.strptime( pblEventEditorFormDetails.startTime.data, "%H:%M" ).time() endTime = datetime.strptime( pblEventEditorFormDetails.endTime.data, "%H:%M" ).time() log.startTime = startTime log.endTime = endTime log.eventLocation = pblEventEditorFormDetails.eventLocation.data log.eventStreetAddress1 = pblEventEditorFormDetails.eventStreetAddress1.data log.eventCity = pblEventEditorFormDetails.eventCity.data log.eventState = pblEventEditorFormDetails.eventState.data log.eventZip = pblEventEditorFormDetails.eventZip.data log.eventComments = pblEventEditorFormDetails.eventComments.data # Add event to GoogleCalendar if it has date and times if log.eventDate and startTime and endTime: googleCalendarEventID = addPblEventToCalendar( log.googleCalendarEventID, log.eventCategory, log.Pbls.pblName, log.eventDate, log.eventLocation, log.eventStreetAddress1, log.eventCity, log.eventState, log.eventZip, startTime, endTime, log.Pbls.pblSponsorPersonName, ) log.googleCalendarEventID = googleCalendarEventID # If the eventDate has been cleared, delete the event from Google Calendar if log.eventDate == None and log.googleCalendarEventID: deletePblEventFromCalendar(log.googleCalendarEventID) log.googleCalendarEventID = None db.session.commit() return redirect( url_for( "pblPlanner_bp.displayStemIIIPblPlanner", selectedQuarter=event_quarter, ) ) pblName = log.Pbls.pblName print("pblName =", pblName) if log: pblEventEditorFormDetails.log_id.data = log.id pblEventEditorFormDetails.eventCategory.data = log.eventCategory pblEventEditorFormDetails.confirmed.data = log.confirmed pblEventEditorFormDetails.eventDate.data = log.eventDate pblEventEditorFormDetails.startTime.data = log.startTime.strftime("%H:%M") pblEventEditorFormDetails.endTime.data = log.endTime.strftime("%H:%M") pblEventEditorFormDetails.eventLocation.data = log.eventLocation pblEventEditorFormDetails.eventStreetAddress1.data = log.eventStreetAddress1 pblEventEditorFormDetails.eventCity.data = log.eventCity pblEventEditorFormDetails.eventState.data = log.eventState pblEventEditorFormDetails.eventZip.data = log.eventZip pblEventEditorFormDetails.eventComments.data = log.eventComments print( "editPblEventDetails=", pblEventEditorFormDetails.log_id.data, pblEventEditorFormDetails.eventCategory.data, ) return render_template( "pbleventeditor.html", title="PBL Event Editor", pblEventEditorForm=pblEventEditorFormDetails, pblName=pblName, event_quarter=event_quarter, )
def new_PblEvent(pbl_id): pblEventEditorFormDetails = pblEventEditorForm() pblLog = Pbls.query.get_or_404(pbl_id) pblName = pblLog.pblName event_quarter = pblLog.quarter pblEventEditorFormDetails.eventCategory.choices = getPblEventCategoryChoices() pblEventEditorFormDetails.log_id.data = 0 printLogEntry("Running new_PblEvent()") if "submitEditPblEvent" in request.form: print("request.form", request.form) if not pblEventEditorFormDetails.validate_on_submit(): print("Edit PBL Event Form errors") printFormErrors(pblEventEditorFormDetails) if pblEventEditorFormDetails.validate_on_submit(): print("submitEditPblEvent submitted") # Update the database with the values submitted in the form eventCategory = pblEventEditorFormDetails.eventCategory.data confirmed = pblEventEditorFormDetails.confirmed.data eventDate = pblEventEditorFormDetails.eventDate.data # Format time values from string objects to time objects startTime = datetime.strptime( pblEventEditorFormDetails.startTime.data, "%H:%M" ).time() endTime = datetime.strptime( pblEventEditorFormDetails.endTime.data, "%H:%M" ).time() eventLocation = pblEventEditorFormDetails.eventLocation.data eventStreetAddress1 = pblEventEditorFormDetails.eventStreetAddress1.data eventCity = pblEventEditorFormDetails.eventCity.data eventState = pblEventEditorFormDetails.eventState.data eventZip = pblEventEditorFormDetails.eventZip.data eventComments = pblEventEditorFormDetails.eventComments.data googleCalendarEventID = None # Add event to GoogleCalendar if it has date and times if eventDate and startTime and endTime: googleCalendarEventID = addPblEventToCalendar( googleCalendarEventID, eventCategory, pblName, eventDate, eventLocation, eventStreetAddress1, eventCity, eventState, eventZip, startTime, endTime, pblLog.pblSponsorPersonName, ) googleCalendarEventID = googleCalendarEventID pblEventLog = PblEvents( pbl_id=pbl_id, eventCategory=eventCategory, confirmed=confirmed, eventDate=eventDate, startTime=startTime, endTime=endTime, eventLocation=eventLocation, eventStreetAddress1=eventStreetAddress1, eventCity=eventCity, eventState=eventState, eventZip=eventZip, eventComments=eventComments, googleCalendarEventID=googleCalendarEventID, ) db.session.add(pblEventLog) db.session.commit() return redirect(url_for("pblPlanner_bp.displayStemIIIPblPlanner")) return render_template( "pbleventeditor.html", title="New PBL Event Editor", pblEventEditorForm=pblEventEditorFormDetails, pblName=pblName, event_quarter=event_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 edit_ClassSchedule(log_id): editSingleClassScheduleDetails = editSingleClassSchedule() editSingleClassScheduleDetails.schoolYear.choices = getSchoolYear() editSingleClassScheduleDetails.semester.choices = getSemester() editSingleClassScheduleDetails.teacherName.choices = getTeachers() editSingleClassScheduleDetails.campus.choices = getCampusChoices() editSingleClassScheduleDetails.className.choices = getStemAndChattStateClassNames( ) editSingleClassScheduleDetails.classDays.choices = [ ("M", "M"), ("T", "T"), ("W", "W"), ("R", "R"), ("F", "F"), ] log = ClassSchedule.query.get_or_404(log_id) LogDetails = f"{(log_id)} {log.chattStateANumber} {log.className}" printLogEntry("Running update_ClassSchedule(" + LogDetails + ")") if "submitEditSingleClassSchedule" in request.form: print("request.form", request.form) if not editSingleClassScheduleDetails.validate_on_submit(): print("Edit Class Form errors") printFormErrors(editSingleClassScheduleDetails) if editSingleClassScheduleDetails.validate_on_submit(): print("submitEditSingleClassSchedule submitted") # Get the pre-update class days and times for use in log comment later preUpdateClassDays = log.classDays preUpdateStartTime = log.startTime preUpdateEndTime = log.endTime # Update the database with the values submitted in the form log.schoolYear = editSingleClassScheduleDetails.schoolYear.data log.semester = editSingleClassScheduleDetails.semester.data log.campus = editSingleClassScheduleDetails.campus.data log.className = editSingleClassScheduleDetails.className.data log.teacherLastName = editSingleClassScheduleDetails.teacherName.data classDaysList = editSingleClassScheduleDetails.classDays.data classDays = "" for classDay in classDaysList: classDays = classDays + classDay print("classDaysList=", classDaysList) # Set updatedClassDays to True if the classDays are updated # updatedClassDays is used to determine whether to delete attendance logs if classDays == preUpdateClassDays: updatedClassDays = False else: updatedClassDays = True log.classDays = classDays startTime = editSingleClassScheduleDetails.startTime.data endTime = editSingleClassScheduleDetails.endTime.data updatedTimes = False # Set updatedTimes to True if the class times are updated # updatedTimes is used to determine whether to append comment to attendance logs if startTime != preUpdateStartTime: updatedTimes = True log.startTime = startTime if endTime != preUpdateEndTime: updatedTimes = True log.endTime = endTime log.online = editSingleClassScheduleDetails.online.data log.indStudy = editSingleClassScheduleDetails.indStudy.data log.comment = editSingleClassScheduleDetails.comment.data log.googleCalendarEventID = ( editSingleClassScheduleDetails.googleCalendarEventID.data) db.session.commit() # If classDays change, delete any class attendance logs that are null # If logs have attendance code, append a comment explaining the original class days and times # If class days or class times changes, append a comment on logs with an attendance code if updatedClassDays or updatedTimes: print( "classDays or class times updated -- reviewing associated class attendance logs" ) attendanceLogs = ClassAttendanceLog.query.filter( ClassAttendanceLog.classSchedule_id == log.id).all() for attendanceLog in attendanceLogs: # Delete class logs with null attendance codes and new days if attendanceLog.attendanceCode == None and updatedClassDays: db.session.delete(attendanceLog) db.session.commit() print( "Deleting attendance log for ", log.className, "on", attendanceLog.classDate, ) # Append comment to logs with attendance codes noting the original class schedule info if attendanceLog.attendanceCode != None and ( updatedTimes or updatedClassDays): scheduleComment = ( "[Class schedule changed from: " + preUpdateClassDays + " " + preUpdateStartTime.strftime("%-I:%M") + "-" + preUpdateEndTime.strftime("%-I:%M") + " on " + date.today().strftime("%-m/%-d/%Y") + "] ") if attendanceLog.comment == None: attendanceLog.comment = "" attendanceLog.comment = scheduleComment + attendanceLog.comment db.session.commit() print("Appending attendanceLog.comment:", attendanceLog.comment) return redirect(url_for("masterSchedule_bp.displayMasterSchedule")) studentName = getStudentName(log.chattStateANumber) print("studentName =", studentName) if log: # editSingleClassScheduleDetails.schoolYear.choices = getSchoolYear() # editSingleClassScheduleDetails.semester.choices = getSemester() # editSingleClassScheduleDetails.teacherName.choices = getTeachers() # editSingleClassScheduleDetails.campus.choices = getCampusChoices() # editSingleClassScheduleDetails.className.choices = ( # getStemAndChattStateClassNames() # ) # editSingleClassScheduleDetails.classDays.choices = [ # ("M", "M"), # ("T", "T"), # ("W", "W"), # ("R", "R"), # ("F", "F"), # ] editSingleClassScheduleDetails.log_id.data = log.id editSingleClassScheduleDetails.schoolYear.data = log.schoolYear editSingleClassScheduleDetails.semester.data = log.semester editSingleClassScheduleDetails.campus.data = log.campus editSingleClassScheduleDetails.className.data = log.className editSingleClassScheduleDetails.teacherName.data = log.teacherLastName # Set classDays by creating list of days from string (e.g., 'MWF' -> [M, W, F]) classDaysList = [] for classDay in log.classDays: classDaysList.append(classDay) editSingleClassScheduleDetails.classDays.data = classDaysList editSingleClassScheduleDetails.startTime.data = log.startTime editSingleClassScheduleDetails.endTime.data = log.endTime editSingleClassScheduleDetails.online.data = log.online editSingleClassScheduleDetails.indStudy.data = log.indStudy editSingleClassScheduleDetails.comment.data = log.comment editSingleClassScheduleDetails.googleCalendarEventID.data = ( log.googleCalendarEventID) print( "editSingleClassScheduleDetails=", editSingleClassScheduleDetails.log_id.data, editSingleClassScheduleDetails.schoolYear.data, editSingleClassScheduleDetails.classDays.data, ) return render_template( "updatemasterschedule.html", title="Update Master Schedule", editSingleClassSchedule=editSingleClassScheduleDetails, studentName=studentName, )