Ejemplo n.º 1
0
def updateParents(chattStateANumber):
    printLogEntry("Running updateParents()")
    parents = Parents.query.filter(
        Parents.chattStateANumber == chattStateANumber).first()
    # If no parents found, create a blank parents record in the Parents table
    if parents is None:
        addParentsToDatabase(
            chattStateANumber,
            guardianship=None,
            motherName=None,
            motherEmail=None,
            motherHomePhone=None,
            motherDayPhone=None,
            fatherName=None,
            fatherEmail=None,
            fatherHomePhone=None,
            fatherDayPhone=None,
            guardianEmail=None,
            comment=None,
        )
        parents = Parents.query.filter(
            Parents.chattStateANumber == chattStateANumber).first()
    studentName = getStudentName(chattStateANumber)
    updateParentsFormDetails = updateParentsForm()
    if "submitUpdateParents" in request.form:
        if updateParentsFormDetails.validate_on_submit():
            parents.guardianship = updateParentsFormDetails.guardianship.data
            parents.motherName = updateParentsFormDetails.motherName.data
            parents.motherEmail = updateParentsFormDetails.motherEmail.data
            parents.motherHomePhone = updateParentsFormDetails.motherHomePhone.data
            parents.motherDayPhone = updateParentsFormDetails.motherDayPhone.data
            parents.fatherName = updateParentsFormDetails.fatherName.data
            parents.fatherEmail = updateParentsFormDetails.fatherEmail.data
            parents.fatherHomePhone = updateParentsFormDetails.fatherHomePhone.data
            parents.fatherDayPhone = updateParentsFormDetails.fatherDayPhone.data
            parents.guardianEmail = updateParentsFormDetails.guardianEmail.data
            parents.comment = updateParentsFormDetails.comment.data
            db.session.commit()
            parentsUpdateString = (parents.chattStateANumber + " " +
                                   parents.motherName + " " +
                                   parents.fatherName)
            printLogEntry("Parent info updated for " + parentsUpdateString)
            flash("Parents details for " + parentsUpdateString + " updated!",
                  "success")
            return redirect(url_for("p2mtAdmin_bp.displayP2MTAdmin"))
    elif request.method == "GET":
        updateParentsFormDetails.chattStateANumber.data = parents.chattStateANumber
        updateParentsFormDetails.guardianship.data = parents.guardianship
        updateParentsFormDetails.motherName.data = parents.motherName
        updateParentsFormDetails.motherEmail.data = parents.motherEmail
        updateParentsFormDetails.motherHomePhone.data = parents.motherHomePhone
        updateParentsFormDetails.motherDayPhone.data = parents.motherDayPhone
        updateParentsFormDetails.fatherName.data = parents.fatherName
        updateParentsFormDetails.fatherEmail.data = parents.fatherEmail
        updateParentsFormDetails.fatherHomePhone.data = parents.fatherHomePhone
        updateParentsFormDetails.fatherDayPhone.data = parents.fatherDayPhone
        updateParentsFormDetails.guardianEmail.data = parents.guardianEmail
        updateParentsFormDetails.comment.data = parents.comment
    return render_template(
        "updateparents.html",
        title="Update Parents",
        updateParentsForm=updateParentsFormDetails,
        studentName=studentName,
    )
Ejemplo n.º 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,
    )