Exemplo n.º 1
0
def displayClassAbsenceLog():
    printLogEntry("displayClassAbsenceLog() function called")
    start_of_current_school_year = get_start_of_current_school_year()
    end_of_current_school_year = get_end_of_current_school_year()
    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.attendanceCode == "U",
            ClassAttendanceLog.classDate >= start_of_current_school_year,
            ClassAttendanceLog.classDate <= end_of_current_school_year,
        )
        .order_by(
            ClassAttendanceLog.classDate.desc(),
            Student.lastName,
            ClassSchedule.className,
        )
        .all()
    )

    return render_template(
        "classabsencelog.html",
        title="Class Absence Log",
        classAttendanceFixedFields=classAttendanceFixedFields,
    )
Exemplo n.º 2
0
def displayDailyAttendanceLogs():
    printLogEntry("displayDailyAttendanceLogs() function called")
    start_of_current_school_year = get_start_of_current_school_year()
    end_of_current_school_year = get_end_of_current_school_year()
    DailyAttendanceLogs = DailyAttendanceLog.query.filter(
        DailyAttendanceLog.absenceDate >= start_of_current_school_year,
        DailyAttendanceLog.absenceDate <= end_of_current_school_year,
    ).order_by(DailyAttendanceLog.absenceDate.desc())
    return render_template(
        "dailyattendancelog.html",
        title="Absence Log",
        DailyAttendanceLogs=DailyAttendanceLogs,
    )
Exemplo n.º 3
0
def downloadInterventionLog():
    printLogEntry("downloadDailyAttendanceLog() function called")
    # Create a CSV output file and append with a timestamp
    output_file_path = os.path.join(current_app.root_path, "static/download")
    output_file_path = "/tmp"
    timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
    csvFilename = output_file_path + "/" + "intervention_log_" + timestamp + ".csv"
    csvOutputFile = open(csvFilename, "w")
    csvOutputWriter = csv.writer(csvOutputFile,
                                 delimiter=",",
                                 quotechar='"',
                                 quoting=csv.QUOTE_MINIMAL)
    # Write header row for CSV file
    csvOutputWriter.writerow([
        "chattStateANumber",
        "firstName",
        "lastName",
        "interventionType",
        "interventionLevel",
        "logEntryDate",
        "startDate",
        "endDate",
        "staffLastName",
        "comment",
    ])
    csvOutputFileRowCount = 0
    # Query for information
    start_of_current_school_year = get_start_of_current_school_year()
    end_of_current_school_year = get_end_of_current_school_year()
    interventionLogs = (InterventionLog.query.join(InterventionType).join(
        Student).join(FacultyAndStaff).filter(
            InterventionLog.createDate >= start_of_current_school_year,
            InterventionLog.createDate <= end_of_current_school_year,
        ).order_by(Student.lastName).all())
    # Process each record in the query and write to the output file
    for log in interventionLogs:
        csvOutputWriter.writerow([
            log.Student.chattStateANumber,
            log.Student.firstName,
            log.Student.lastName,
            log.InterventionType.interventionType,
            log.interventionLevel,
            log.createDate,
            log.startDate,
            log.endDate,
            log.FacultyAndStaff.lastName,
            log.comment,
        ])
        csvOutputFileRowCount = csvOutputFileRowCount + 1
    csvOutputFile.close()
    return send_file(csvFilename, as_attachment=True, cache_timeout=0)
Exemplo n.º 4
0
def displayInterventionLogs():
    printLogEntry("Running displayInterventionLogs()")
    start_of_current_school_year = get_start_of_current_school_year()
    end_of_current_school_year = get_end_of_current_school_year()
    InterventionLogs = InterventionLog.query.filter(
        InterventionLog.parentNotification != None,
        InterventionLog.createDate >= start_of_current_school_year,
        InterventionLog.createDate <= end_of_current_school_year,
    ).order_by(InterventionLog.endDate.desc())

    return render_template(
        "interventionlog.html",
        title="Intervention Log",
        InterventionLogs=InterventionLogs,
    )
Exemplo n.º 5
0
def displayStudentInfo():
    """Display student info page with the following info:
    Student name, email, house, year of graduation
    Parent info
    Absences
    Class attendance (when not present)
    Interventions
    Learning labs
    Class schedule
    """
    printLogEntry("Running displayStudentInfo()")
    chattStateANumber = request.args["chattStateANumber"]
    print("chattStateANumber = ", chattStateANumber)

    start_of_current_school_year = get_start_of_current_school_year()
    end_of_current_school_year = get_end_of_current_school_year()

    students = Student.query.filter(
        Student.chattStateANumber == chattStateANumber
    ).order_by(Student.yearOfGraduation.asc(), Student.lastName.asc())

    parents = (
        Parents.query.join(Student)
        .filter(Student.chattStateANumber == chattStateANumber)
        .order_by(Student.lastName.asc())
    )

    DailyAttendanceLogs = (
        DailyAttendanceLog.query.filter(
            DailyAttendanceLog.chattStateANumber == chattStateANumber
        )
        .filter(
            DailyAttendanceLog.createDate >= start_of_current_school_year,
            DailyAttendanceLog.createDate <= end_of_current_school_year,
        )
        .order_by(DailyAttendanceLog.absenceDate.desc())
    )

    classAttendanceFixedFields = (
        ClassAttendanceLog.query.filter(ClassAttendanceLog.attendanceCode != "P")
        .filter(ClassSchedule.chattStateANumber == chattStateANumber)
        .join(ClassSchedule)
        .join(ClassSchedule.Student)
        .filter(
            ClassAttendanceLog.classDate >= start_of_current_school_year,
            ClassAttendanceLog.classDate <= end_of_current_school_year,
        )
        .order_by(
            Student.lastName,
            ClassAttendanceLog.classDate.desc(),
            ClassSchedule.className,
        )
        .all()
    )

    InterventionLogs = (
        InterventionLog.query.filter(
            InterventionLog.parentNotification != None,
            InterventionLog.chattStateANumber == chattStateANumber,
        )
        .filter(
            InterventionLog.createDate >= start_of_current_school_year,
            InterventionLog.createDate <= end_of_current_school_year,
        )
        .order_by(InterventionLog.endDate.desc())
    )

    ClassSchedules = (
        ClassSchedule.query.filter(
            ClassSchedule.learningLab == False,
            ClassSchedule.chattStateANumber == chattStateANumber,
        )
        .filter(
            or_(
                and_(
                    ClassSchedule.schoolYear == getSchoolYearForFallSemester(),
                    ClassSchedule.semester == "Fall",
                ),
                and_(
                    ClassSchedule.schoolYear == getSchoolYearForSpringSemester(),
                    ClassSchedule.semester == "Spring",
                ),
            ),
        )
        .order_by(ClassSchedule.chattStateANumber.desc())
    )

    LearningLabSchedules = (
        db.session.query(ClassSchedule)
        .join(InterventionLog)
        .join(Student)
        .filter(
            ClassSchedule.learningLab == True,
            ClassSchedule.chattStateANumber == chattStateANumber,
            or_(
                and_(
                    ClassSchedule.schoolYear == getSchoolYearForFallSemester(),
                    ClassSchedule.semester == "Fall",
                ),
                and_(
                    ClassSchedule.schoolYear == getSchoolYearForSpringSemester(),
                    ClassSchedule.semester == "Spring",
                ),
            ),
        )
        .order_by(InterventionLog.endDate.desc(), Student.lastName.asc())
    ).all()

    return render_template(
        "studentinfo.html",
        title="Student Info",
        students=students,
        parents=parents,
        DailyAttendanceLogs=DailyAttendanceLogs,
        classAttendanceFixedFields=classAttendanceFixedFields,
        InterventionLogs=InterventionLogs,
        ClassSchedules=ClassSchedules,
        LearningLabSchedules=LearningLabSchedules,
    )
Exemplo n.º 6
0
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,
    )