예제 #1
0
def displayClassAttendanceLog():
    printLogEntry("Running displayClassAttendanceLog()")
    classAttendanceForm = updateClassAttendanceForm()
    classAttendanceForm.teacherName.choices = getTeachers()
    # Update class choices to remove blank choice and include "All Classes" as default
    classNameChoices = list(getClassNames())
    classNameChoices.remove(("", ""))
    classNameChoices.insert(0, ("All Classes", "All Classes"))
    classAttendanceForm.className.choices = tuple(classNameChoices)

    classDateTime = date.today()
    # classDateTime = datetime(
    #     datetime.today().year, datetime.today().month, datetime.today().day, 0, 0, 0, 0
    # )
    # print(
    #     "\nclassAttendanceForm.identifier.data = ", classAttendanceForm.identifier.data
    # )
    print(
        "classAttendanceForm.updateFiltersFlag.data =",
        classAttendanceForm.updateFiltersFlag.data,
    )

    print("request.method =", request.method)

    if classAttendanceForm.validate_on_submit():
        print(
            "classAttendanceForm.validate_on_submit() =",
            classAttendanceForm.validate_on_submit(),
        )
    print("classAttendanceForm.errors =", classAttendanceForm.errors)

    # if classAttendanceForm.identifier.data is None:
    if request.method == "GET":

        if classAttendanceForm.classDate.data:
            classDateTime = classAttendanceForm.classDate.data
            classAttendanceForm.classDate.default = classDateTime
        else:
            classDateTime = date.today()
            # classDateTime = datetime.now()
            # classDateTime = classDateTime.replace(
            #     hour=0, minute=0, second=0, microsecond=0
            # )
            classAttendanceForm.classDate.data = classDateTime
            # classAttendanceForm.classDate.data = classDateTime.date()

        classAttendanceForm.className.default = classAttendanceForm.className.data
        classAttendanceForm.teacherName.default = classAttendanceForm.teacherName.data
        classAttendanceForm.updateFiltersFlag.data = ""

    if classAttendanceForm.validate_on_submit():

        # Update default values for teacher name and class name
        classAttendanceForm.className.default = classAttendanceForm.className.data
        classAttendanceForm.teacherName.default = classAttendanceForm.teacherName.data

        # Format class date for compatibility with database
        classDate = classAttendanceForm.classDate.data
        classDateTime = classDate
        print(classDate, classDateTime)
        # classDateTime = datetime(
        #     classDate.year, classDate.month, classDate.day, 0, 0, 0, 0
        # )
        print(
            "classAttendanceForm.updateFiltersFlag.data =",
            classAttendanceForm.updateFiltersFlag.data,
        )

        # Update database with attendance updates
        if (classAttendanceForm.classMembers
                and classAttendanceForm.updateFiltersFlag.data != "updated"):
            print("Class attendance submitted")
            print(len(classAttendanceForm.classMembers.data))
            for studentForm in classAttendanceForm.classMembers.data:
                if studentForm["updateFlag"] == "updated":
                    # Record updated attendance for student
                    log_id = studentForm["log_id"]
                    print("log_id = ", log_id)
                    classAttendanceLog = ClassAttendanceLog.query.get_or_404(
                        log_id)
                    classAttendanceLog.attendanceCode = studentForm[
                        "attendanceCode"]
                    classAttendanceLog.comment = studentForm["comment"]

                    # Don't mark assignTmi for missed learning labs
                    learningLab = classAttendanceLog.ClassSchedule.learningLab
                    if classAttendanceLog.attendanceCode == "P" and not learningLab:
                        classAttendanceLog.assignTmi = False
                    if classAttendanceLog.attendanceCode == "E" and not learningLab:
                        classAttendanceLog.assignTmi = False
                    # if classAttendanceLog.attendanceCode == "T":
                    #     classAttendanceLog.assignTmi = False
                    if classAttendanceLog.attendanceCode == "U" and not learningLab:
                        classAttendanceLog.assignTmi = True
                    if classAttendanceLog.attendanceCode == "Q" and not learningLab:
                        classAttendanceLog.assignTmi = True
                    db.session.commit()

        # Need to run the next statement [classAttendanceForm.process()]
        # or the updated values for the studentAttendanceForm won't display
        classAttendanceForm.process()

    # Retrive updated fixed-value attendance fields from database

    # If "All Classes" is selected, display all clases
    # Otherwise, only display classes for selecetd class
    if classAttendanceForm.className.default == "All Classes":
        print("All classes selected")
        classAttendanceFixedFields = (db.session.query(
            ClassAttendanceLog, ClassSchedule,
            DailyAttendanceLog).select_from(ClassAttendanceLog).join(
                ClassSchedule).join(ClassSchedule.Student).outerjoin(
                    DailyAttendanceLog,
                    (ClassAttendanceLog.classDate
                     == DailyAttendanceLog.absenceDate)
                    & (ClassSchedule.chattStateANumber
                       == DailyAttendanceLog.chattStateANumber),
                ).filter(
                    ClassAttendanceLog.classDate == classDateTime,
                    ClassSchedule.teacherLastName ==
                    classAttendanceForm.teacherName.default,
                ).order_by(ClassSchedule.startTime, ClassSchedule.className,
                           Student.lastName).all())
    else:
        classAttendanceFixedFields = (db.session.query(
            ClassAttendanceLog, ClassSchedule, DailyAttendanceLog
        ).select_from(ClassAttendanceLog).join(ClassSchedule).join(
            ClassSchedule.Student
        ).outerjoin(
            DailyAttendanceLog,
            (ClassAttendanceLog.classDate == DailyAttendanceLog.absenceDate)
            & (ClassSchedule.chattStateANumber
               == DailyAttendanceLog.chattStateANumber),
        ).filter(
            ClassAttendanceLog.classDate == classDateTime,
            ClassSchedule.teacherLastName ==
            classAttendanceForm.teacherName.default,
            ClassSchedule.className == classAttendanceForm.className.default,
        ).order_by(ClassSchedule.startTime, ClassSchedule.className,
                   Student.lastName).all())

    # Retrieve updated student attendance fields from database
    for studentAttendance in classAttendanceFixedFields:
        print(studentAttendance)
        studentAttendanceForm = updateStudentAttendanceForm()
        studentAttendanceForm.log_id = studentAttendance.ClassAttendanceLog.id
        studentAttendanceForm.attendanceCode = (
            studentAttendance.ClassAttendanceLog.attendanceCode)
        studentAttendanceForm.comment = studentAttendance.ClassAttendanceLog.comment
        studentAttendanceForm.updateFlag = ""
        print(
            "ROSTER ",
            studentAttendanceForm.log_id,
            studentAttendance.ClassSchedule.className,
            studentAttendance.ClassSchedule.startTime,
            studentAttendance.ClassSchedule.endTime,
            studentAttendance.ClassSchedule.Student.firstName,
            studentAttendance.ClassSchedule.Student.lastName,
            studentAttendanceForm.attendanceCode,
            studentAttendanceForm.comment,
        )
        classAttendanceForm.classMembers.append_entry(studentAttendanceForm)

    # Reset the updateFiltersFlag before rendering page
    classAttendanceForm.updateFiltersFlag.data = ""

    print("Final before render_template")
    print(
        "classAttendanceForm.classDate.default =",
        classAttendanceForm.classDate.default,
    )
    print(
        "classAttendanceForm.classDate.data =",
        classAttendanceForm.classDate.data,
    )
    return render_template(
        "classattendancelog.html",
        title="Attendance Log",
        classAttendanceForm=classAttendanceForm,
        classAttendanceFixedFields=classAttendanceFixedFields,
    )
예제 #2
0
def edit_ClassSchedule(log_id):
    editSingleClassScheduleDetails = editSingleClassSchedule()
    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("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,
    )
예제 #3
0
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,
    )
예제 #4
0
def displayTmiTeacherReview():
    printLogEntry("Running displayTmiTeacherReview()")
    startTmiPeriod, endTmiPeriod, tmiDay = getCurrent_Start_End_Tmi_Dates()
    tmiTeacherReviewForm = updateTmiTeacherReviewForm()
    tmiTeacherReviewForm.teacherName.choices = getTeachers()

    print(
        "tmiTeacherReviewForm.updateFiltersFlag.data =",
        tmiTeacherReviewForm.updateFiltersFlag.data,
    )

    print("request.method =", request.method)

    if tmiTeacherReviewForm.validate_on_submit():
        print(
            "tmiTeacherReviewForm.validate_on_submit() =",
            tmiTeacherReviewForm.validate_on_submit(),
        )
    print("tmiTeacherReviewForm.errors =", tmiTeacherReviewForm.errors)

    if request.method == "GET":

        tmiTeacherReviewForm.teacherName.default = tmiTeacherReviewForm.teacherName.data
        tmiTeacherReviewForm.updateFiltersFlag.data = ""

    if tmiTeacherReviewForm.validate_on_submit():

        # Update default values for teacher name and class name
        tmiTeacherReviewForm.teacherName.default = tmiTeacherReviewForm.teacherName.data

        print(
            "tmiTeacherReviewForm.updateFiltersFlag.data =",
            tmiTeacherReviewForm.updateFiltersFlag.data,
        )

        # Update database with attendance updates
        if (
            tmiTeacherReviewForm.classMembers
            and tmiTeacherReviewForm.updateFiltersFlag.data != "updated"
        ):
            print("Class attendance submitted")
            print(len(tmiTeacherReviewForm.classMembers.data))
            for studentForm in tmiTeacherReviewForm.classMembers.data:
                if studentForm["updateFlag"] == "updated":
                    log_id = studentForm["log_id"]
                    print("log_id = ", log_id)
                    classAttendanceLog = ClassAttendanceLog.query.get_or_404(log_id)
                    classAttendanceLog.attendanceCode = studentForm["attendanceCode"]
                    classAttendanceLog.comment = studentForm["comment"]
                    if classAttendanceLog.attendanceCode == "P":
                        classAttendanceLog.assignTmi = False
                    if classAttendanceLog.attendanceCode == "E":
                        classAttendanceLog.assignTmi = studentForm["assignTmi"]
                    # if classAttendanceLog.attendanceCode == "T":
                    #     classAttendanceLog.assignTmi = False
                    if classAttendanceLog.attendanceCode == "U":
                        classAttendanceLog.assignTmi = True
                    if classAttendanceLog.attendanceCode == "Q":
                        classAttendanceLog.assignTmi = True
                    db.session.commit()

        # Need to run the next statement [classAttendanceForm.process()]
        # or the updated values for the studentAttendanceForm won't display
        tmiTeacherReviewForm.process()

    # Update TMI status for tardy students which is based on tardies
    # for other classes
    assignTmiForTardy(startTmiPeriod, endTmiPeriod)
    db.session.commit()

    # Retrive updated fixed-value attendance fields from database
    classAttendanceFixedFields = (
        ClassAttendanceLog.query.filter(
            ClassAttendanceLog.classDate >= startTmiPeriod,
            ClassAttendanceLog.classDate <= endTmiPeriod,
        )
        .filter(
            (ClassAttendanceLog.attendanceCode == None)
            | (ClassAttendanceLog.attendanceCode != "P")
        )
        .join(ClassSchedule)
        .join(ClassSchedule.Student)
        .filter(
            ClassSchedule.teacherLastName == tmiTeacherReviewForm.teacherName.default
        )
        .order_by(ClassAttendanceLog.classDate)
        .order_by(Student.lastName)
        .all()
    )

    # Retrieve updated student attendance fields from database
    for studentAttendance in classAttendanceFixedFields:
        studentAttendanceForm = updateStudentAttendanceForm()
        studentAttendanceForm.log_id = studentAttendance.id
        studentAttendanceForm.attendanceCode = studentAttendance.attendanceCode
        studentAttendanceForm.comment = studentAttendance.comment
        studentAttendanceForm.assignTmi = studentAttendance.assignTmi
        studentAttendanceForm.updateFlag = ""
        print(
            "ROSTER ",
            studentAttendanceForm.log_id,
            studentAttendance.ClassSchedule.className,
            studentAttendance.ClassSchedule.startTime,
            studentAttendance.ClassSchedule.endTime,
            studentAttendance.ClassSchedule.Student.firstName,
            studentAttendance.ClassSchedule.Student.lastName,
            studentAttendanceForm.attendanceCode,
            studentAttendanceForm.comment,
            studentAttendanceForm.assignTmi,
        )
        tmiTeacherReviewForm.classMembers.append_entry(studentAttendanceForm)

    # Reset the updateFiltersFlag before rendering page
    tmiTeacherReviewForm.updateFiltersFlag.data = ""

    return render_template(
        "tmiteacherreview.html",
        title="TMI Teacher Review",
        classAttendanceForm=tmiTeacherReviewForm,
        classAttendanceFixedFields=classAttendanceFixedFields,
        startTmiPeriod=startTmiPeriod,
        endTmiPeriod=endTmiPeriod,
        tmiDay=tmiDay,
    )
예제 #5
0
파일: routes.py 프로젝트: phase2team/P2MT
def displayLearningLab():
    printLogEntry("Running displayLearningLab()")
    # Learning lab uses the same form as adding a single class schedule
    # This form includes several fields which can be pre-set rather
    # than including the fields on the form
    # Pre-setting the fields will avoid form validation errors later
    addLearningLabDetails = addLearningLabToSchedule()
    # Pre-set campus equal to STEM School
    addLearningLabDetails.campus.choices = getCampusChoices()
    addLearningLabDetails.campus.data = "STEM School"
    # Pre-set school year to current school year
    addLearningLabDetails.schoolYear.choices = getSchoolYear()
    addLearningLabDetails.schoolYear.data = getCurrentSchoolYear()
    # Pre-set semester to current semester
    addLearningLabDetails.semester.choices = getSemester()
    addLearningLabDetails.semester.data = getCurrentSemester()
    addLearningLabDetails.teacherName.choices = getTeachers(
        use_staff_list=True)
    addLearningLabDetails.studentName.choices = getStudents()
    addLearningLabDetails.className.choices = getClassNames(campus="All")
    addLearningLabDetails.classDays.choices = getClassDayChoices()
    addLearningLabDetails.classDays2.choices = getClassDayChoices()
    addLearningLabDetails.classDays3.choices = getClassDayChoices()
    addLearningLabDetails.classDays4.choices = getClassDayChoices()
    addLearningLabDetails.classDays5.choices = getClassDayChoices()
    addLearningLabDetails.submitAddSingleClassSchedule.label.text = (
        "Submit New Learning Lab")
    print(request.form)
    # Handle form submission for adding new learning lab
    if "submitAddSingleClassSchedule" in request.form:
        if addLearningLabDetails.validate_on_submit():
            printLogEntry("Add Learning Lab submitted")

            schoolYear = addLearningLabDetails.schoolYear.data
            semester = addLearningLabDetails.semester.data
            chattStateANumber = addLearningLabDetails.studentName.data
            teacherLastName = addLearningLabDetails.teacherName.data
            className = addLearningLabDetails.className.data
            startDate = addLearningLabDetails.startDate.data
            endDate = addLearningLabDetails.endDate.data
            online = addLearningLabDetails.online.data
            indStudy = addLearningLabDetails.indStudy.data
            comment = addLearningLabDetails.comment.data
            googleCalendarEventID = addLearningLabDetails.googleCalendarEventID.data
            campus = "STEM School"
            staffID = current_user.id
            learningLab = True

            print(
                schoolYear,
                semester,
                chattStateANumber,
                teacherLastName,
                className,
                online,
                indStudy,
                comment,
                googleCalendarEventID,
                learningLab,
            )

            printLogEntry("Adding intervention")
            interventionType = 2
            interventionLevel = 1
            interventionLog = add_InterventionLog(
                chattStateANumber,
                interventionType,
                interventionLevel,
                startDate,
                endDate,
                comment,
                parentNotification=datetime.utcnow(),
            )
            db.session.commit()
            print("new intervention log ID:", interventionLog.id)
            # Store all of the common fields in a single variable for later use
            learningLabCommonFields = [
                schoolYear,
                semester,
                chattStateANumber,
                campus,
                className,
                teacherLastName,
                staffID,
                online,
                indStudy,
                comment,
                googleCalendarEventID,
                interventionLog.id,
                learningLab,
                startDate,
                endDate,
            ]
            # Initialize a list to store details of learning labs for email notifications
            learningLabList = []
            # Process each of the five possible entries of learning lab days/time
            if addLearningLabDetails.addTimeAndDays.data:
                print("Adding learning lab time 1")
                # Format time values from string objects to time objects
                startTime = datetime.strptime(
                    addLearningLabDetails.startTime.data, "%H:%M").time()
                endTime = datetime.strptime(addLearningLabDetails.endTime.data,
                                            "%H:%M").time()
                learningLabClassSchedule = addLearningLabTimeAndDays(
                    learningLabCommonFields,
                    addLearningLabDetails.classDays.data,
                    startTime,
                    endTime,
                )
                propagateLearningLab(
                    learningLabClassSchedule.id,
                    startDate,
                    endDate,
                    schoolYear,
                    semester,
                )
                learningLabList = updatelearningLabList(
                    learningLabList,
                    addLearningLabDetails.classDays.data,
                    startTime,
                    endTime,
                )
            if addLearningLabDetails.addTimeAndDays2.data:
                print("Adding learning lab time 2")
                # Format time values from string objects to time objects
                startTime2 = datetime.strptime(
                    addLearningLabDetails.startTime2.data, "%H:%M").time()
                endTime2 = datetime.strptime(
                    addLearningLabDetails.endTime2.data, "%H:%M").time()

                learningLabClassSchedule = addLearningLabTimeAndDays(
                    learningLabCommonFields,
                    addLearningLabDetails.classDays2.data,
                    startTime2,
                    endTime2,
                )
                propagateLearningLab(
                    learningLabClassSchedule.id,
                    startDate,
                    endDate,
                    schoolYear,
                    semester,
                )
                learningLabList = updatelearningLabList(
                    learningLabList,
                    addLearningLabDetails.classDays2.data,
                    startTime2,
                    endTime2,
                )
            if addLearningLabDetails.addTimeAndDays3.data:
                print("Adding learning lab time 3")
                # Format time values from string objects to time objects
                startTime3 = datetime.strptime(
                    addLearningLabDetails.startTime3.data, "%H:%M").time()
                endTime3 = datetime.strptime(
                    addLearningLabDetails.endTime3.data, "%H:%M").time()
                learningLabClassSchedule = addLearningLabTimeAndDays(
                    learningLabCommonFields,
                    addLearningLabDetails.classDays3.data,
                    startTime3,
                    endTime3,
                )
                propagateLearningLab(
                    learningLabClassSchedule.id,
                    startDate,
                    endDate,
                    schoolYear,
                    semester,
                )
                learningLabList = updatelearningLabList(
                    learningLabList,
                    addLearningLabDetails.classDays3.data,
                    startTime3,
                    endTime3,
                )
            if addLearningLabDetails.addTimeAndDays4.data:
                print("Adding learning lab time 4")
                # Format time values from string objects to time objects
                startTime4 = datetime.strptime(
                    addLearningLabDetails.startTime4.data, "%H:%M").time()
                endTime4 = datetime.strptime(
                    addLearningLabDetails.endTime4.data, "%H:%M").time()
                learningLabClassSchedule = addLearningLabTimeAndDays(
                    learningLabCommonFields,
                    addLearningLabDetails.classDays4.data,
                    startTime4,
                    endTime4,
                )
                propagateLearningLab(
                    learningLabClassSchedule.id,
                    startDate,
                    endDate,
                    schoolYear,
                    semester,
                )
                learningLabList = updatelearningLabList(
                    learningLabList,
                    addLearningLabDetails.classDays4.data,
                    startTime4,
                    endTime4,
                )
            if addLearningLabDetails.addTimeAndDays5.data:
                print("Adding learning lab time 5")
                # Format time values from string objects to time objects
                startTime5 = datetime.strptime(
                    addLearningLabDetails.startTime5.data, "%H:%M").time()
                endTime5 = datetime.strptime(
                    addLearningLabDetails.endTime5.data, "%H:%M").time()
                learningLabClassSchedule = addLearningLabTimeAndDays(
                    learningLabCommonFields,
                    addLearningLabDetails.classDays5.data,
                    startTime5,
                    endTime5,
                )
                propagateLearningLab(
                    learningLabClassSchedule.id,
                    startDate,
                    endDate,
                    schoolYear,
                    semester,
                )
                learningLabList = updatelearningLabList(
                    learningLabList,
                    addLearningLabDetails.classDays5.data,
                    startTime5,
                    endTime5,
                )
            print("learningLabList =", learningLabList)
            # Define learning lab parameters for intervention email
            intervention_id = getInterventionId("Academic Behavior")
            interventionLevel = 1
            templateParams = {
                "learningLabList": learningLabList,
                "className": className,
                "teacherLastName": teacherLastName,
            }
            sendInterventionEmail(
                chattStateANumber,
                intervention_id,
                interventionLevel,
                startDate,
                endDate,
                comment,
                templateParams=templateParams,
            )
            return redirect(url_for("learningLab_bp.displayLearningLab"))
    print("addLearningLabDetails.errors: ", addLearningLabDetails.errors)

    # Get list of learning labs to display on learning lab manager
    start_of_current_school_year = get_start_of_current_school_year()
    end_of_current_school_year = get_end_of_current_school_year()
    LearningLabSchedules = (db.session.query(ClassSchedule).join(
        InterventionLog).join(Student).filter(
            ClassSchedule.learningLab == True,
            InterventionLog.endDate >= start_of_current_school_year,
            InterventionLog.endDate <= end_of_current_school_year,
        ).order_by(InterventionLog.endDate.desc(),
                   Student.lastName.asc())).all()

    return render_template(
        "learninglabmanager.html",
        title="Learning Lab",
        addSingleClassSchedule=addLearningLabDetails,
        ClassSchedules=LearningLabSchedules,
    )