Exemple #1
0
def setSystemMode():
    printLogEntry("Running setSystemMode()")
    if request.method == "POST":
        if request.form["submit_button"] == "Set to Test Mode":
            setEmailModeStatus(False)
            db.session.commit()
            print("Enable Live Email =", getEmailModeStatus())
        elif request.form["submit_button"] == "Set to Live Mode":
            setEmailModeStatus(True)
            db.session.commit()
            print("Enable Live Email =", getEmailModeStatus())
    return redirect(url_for("p2mtAdmin_bp.displayP2MTAdmin"))
Exemple #2
0
def sendEmail(email_to, email_cc, emailSubject, emailContent):
    printLogEntry("Running sendEmail()")
    # include the system account as a bcc recipient on all emails
    email_bcc = getSystemAccountEmail()
    # if the email recipient is a list, then use commas to seperate the email addresses
    if isinstance(email_to, list):
        email_to = ",".join(email_to)
    # Retrieve current system mode
    SystemMode = getEmailModeStatus()
    if SystemMode == False:
        print("System Mode = Test. Sending email to", current_user.email)
        email_to = current_user.email
        email_cc = current_user.email
    print(
        "Email Details - to:",
        email_to,
        "cc:",
        email_cc,
        "bcc:",
        email_bcc,
        "subject:",
        emailSubject,
    )
    email_sender = "*****@*****.**"
    message = create_message(email_sender, email_to, email_cc, email_bcc,
                             emailSubject, emailContent)
    # print("message =", message)
    service = service_account_login()
    print("service =", service)
    sent = send_message(service, "*****@*****.**", message)
    print("sent message =", sent)
    return
Exemple #3
0
def sendEmail(email_to, email_cc, emailSubject, emailContent):
    printLogEntry("Running sendEmail()")
    # include the system account as a bcc recipient on all emails
    email_bcc = getSystemAccountEmail()
    # if the email recipient is a list, then use commas to seperate the email addresses
    if isinstance(email_to, list):
        email_to = ",".join(email_to)
    # Retrieve current system mode
    SystemMode = getEmailModeStatus()
    if SystemMode == False:
        print("System Mode = Test. Sending email to", current_user.email)
        email_to = current_user.email
        email_cc = current_user.email
    email_details = f"Email Details - to: {email_to} cc: {email_cc} bcc: {email_bcc} subject: {emailSubject}"
    print(email_details)
    use_azure_send_email = os.getenv("USE_AZURE_SEND_EMAIL",
                                     "False").lower() in [
                                         "true",
                                         "1",
                                     ]
    if use_azure_send_email:
        email_sender = current_user.email
        sent = send_azure_email(email_sender, email_to, email_cc, email_bcc,
                                emailSubject, emailContent)
    else:
        email_sender = "*****@*****.**"
        message = create_message(email_sender, email_to, email_cc, email_bcc,
                                 emailSubject, emailContent)
        # print("message =", message)
        service = service_account_login()
        print("service =", service)
        sent = send_message(service, "*****@*****.**", message)
    print("sent message =", sent)
    if sent is None or sent == False:
        flash_message = f"Error: Unable to send email.  Review {email_details}"
        flash(flash_message, "error")
    else:
        flash("Email notification has been sent!", "success")
    return
Exemple #4
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())

    # Retrieve current system mode
    SystemMode = getEmailModeStatus()

    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,
        SystemMode=SystemMode,
    )