Beispiel #1
0
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,
    )
Beispiel #2
0
def download_StudentList():
    printLogEntry("download_StudentList() function called")
    return downloadStudentList()