Esempio n. 1
0
def download_PblReports():
    printLogEntry("Running download_PblReports()")
    quarterOptions = getQuarterChoices()
    currentQuarter = getCurrentQuarter()
    eventCategoryChoices = getPblEventCategoryChoices()
    return render_template(
        "pblreports.html",
        title="STEM III PBL Reports",
        quarterOptions=quarterOptions,
        displayQuarter=currentQuarter,
        eventCategoryChoices=eventCategoryChoices,
    )
Esempio n. 2
0
def edit_PblEvent(log_id):
    pblEventEditorFormDetails = pblEventEditorForm()
    pblEventEditorFormDetails.eventCategory.choices = getPblEventCategoryChoices()

    log = PblEvents.query.get_or_404(log_id)
    LogDetails = f"{(log_id)} {log.Pbls.pblName} {log.eventCategory}"
    event_quarter = log.Pbls.quarter
    printLogEntry("Running edit_PblEvent(" + LogDetails + ")")

    if "submitEditPblEvent" in request.form:
        print("request.form", request.form)
        if not pblEventEditorFormDetails.validate_on_submit():
            print("Edit PBL Event Form errors")
            printFormErrors(pblEventEditorFormDetails)
        if pblEventEditorFormDetails.validate_on_submit():
            print("submitEditPblEvent submitted")

            # Update the database with the values submitted in the form
            log.eventCategory = pblEventEditorFormDetails.eventCategory.data
            log.confirmed = pblEventEditorFormDetails.confirmed.data
            log.eventDate = pblEventEditorFormDetails.eventDate.data

            # Format time values from string objects to time objects
            startTime = datetime.strptime(
                pblEventEditorFormDetails.startTime.data, "%H:%M"
            ).time()
            endTime = datetime.strptime(
                pblEventEditorFormDetails.endTime.data, "%H:%M"
            ).time()

            log.startTime = startTime
            log.endTime = endTime
            log.eventLocation = pblEventEditorFormDetails.eventLocation.data
            log.eventStreetAddress1 = pblEventEditorFormDetails.eventStreetAddress1.data
            log.eventCity = pblEventEditorFormDetails.eventCity.data
            log.eventState = pblEventEditorFormDetails.eventState.data
            log.eventZip = pblEventEditorFormDetails.eventZip.data
            log.eventComments = pblEventEditorFormDetails.eventComments.data

            # Add event to GoogleCalendar if it has date and times
            if log.eventDate and startTime and endTime:
                googleCalendarEventID = addPblEventToCalendar(
                    log.googleCalendarEventID,
                    log.eventCategory,
                    log.Pbls.pblName,
                    log.eventDate,
                    log.eventLocation,
                    log.eventStreetAddress1,
                    log.eventCity,
                    log.eventState,
                    log.eventZip,
                    startTime,
                    endTime,
                    log.Pbls.pblSponsorPersonName,
                )
                log.googleCalendarEventID = googleCalendarEventID
            # If the eventDate has been cleared, delete the event from Google Calendar
            if log.eventDate == None and log.googleCalendarEventID:
                deletePblEventFromCalendar(log.googleCalendarEventID)
                log.googleCalendarEventID = None

            db.session.commit()
            return redirect(
                url_for(
                    "pblPlanner_bp.displayStemIIIPblPlanner",
                    selectedQuarter=event_quarter,
                )
            )

    pblName = log.Pbls.pblName
    print("pblName =", pblName)
    if log:
        pblEventEditorFormDetails.log_id.data = log.id
        pblEventEditorFormDetails.eventCategory.data = log.eventCategory
        pblEventEditorFormDetails.confirmed.data = log.confirmed
        pblEventEditorFormDetails.eventDate.data = log.eventDate
        pblEventEditorFormDetails.startTime.data = log.startTime.strftime("%H:%M")
        pblEventEditorFormDetails.endTime.data = log.endTime.strftime("%H:%M")
        pblEventEditorFormDetails.eventLocation.data = log.eventLocation
        pblEventEditorFormDetails.eventStreetAddress1.data = log.eventStreetAddress1
        pblEventEditorFormDetails.eventCity.data = log.eventCity
        pblEventEditorFormDetails.eventState.data = log.eventState
        pblEventEditorFormDetails.eventZip.data = log.eventZip
        pblEventEditorFormDetails.eventComments.data = log.eventComments
        print(
            "editPblEventDetails=",
            pblEventEditorFormDetails.log_id.data,
            pblEventEditorFormDetails.eventCategory.data,
        )
    return render_template(
        "pbleventeditor.html",
        title="PBL Event Editor",
        pblEventEditorForm=pblEventEditorFormDetails,
        pblName=pblName,
        event_quarter=event_quarter,
    )
Esempio n. 3
0
def new_PblEvent(pbl_id):
    pblEventEditorFormDetails = pblEventEditorForm()
    pblLog = Pbls.query.get_or_404(pbl_id)
    pblName = pblLog.pblName
    event_quarter = pblLog.quarter
    pblEventEditorFormDetails.eventCategory.choices = getPblEventCategoryChoices()
    pblEventEditorFormDetails.log_id.data = 0

    printLogEntry("Running new_PblEvent()")

    if "submitEditPblEvent" in request.form:
        print("request.form", request.form)
        if not pblEventEditorFormDetails.validate_on_submit():
            print("Edit PBL Event Form errors")
            printFormErrors(pblEventEditorFormDetails)
        if pblEventEditorFormDetails.validate_on_submit():
            print("submitEditPblEvent submitted")

            # Update the database with the values submitted in the form
            eventCategory = pblEventEditorFormDetails.eventCategory.data
            confirmed = pblEventEditorFormDetails.confirmed.data
            eventDate = pblEventEditorFormDetails.eventDate.data

            # Format time values from string objects to time objects
            startTime = datetime.strptime(
                pblEventEditorFormDetails.startTime.data, "%H:%M"
            ).time()
            endTime = datetime.strptime(
                pblEventEditorFormDetails.endTime.data, "%H:%M"
            ).time()

            eventLocation = pblEventEditorFormDetails.eventLocation.data
            eventStreetAddress1 = pblEventEditorFormDetails.eventStreetAddress1.data
            eventCity = pblEventEditorFormDetails.eventCity.data
            eventState = pblEventEditorFormDetails.eventState.data
            eventZip = pblEventEditorFormDetails.eventZip.data
            eventComments = pblEventEditorFormDetails.eventComments.data
            googleCalendarEventID = None

            # Add event to GoogleCalendar if it has date and times
            if eventDate and startTime and endTime:
                googleCalendarEventID = addPblEventToCalendar(
                    googleCalendarEventID,
                    eventCategory,
                    pblName,
                    eventDate,
                    eventLocation,
                    eventStreetAddress1,
                    eventCity,
                    eventState,
                    eventZip,
                    startTime,
                    endTime,
                    pblLog.pblSponsorPersonName,
                )
                googleCalendarEventID = googleCalendarEventID

            pblEventLog = PblEvents(
                pbl_id=pbl_id,
                eventCategory=eventCategory,
                confirmed=confirmed,
                eventDate=eventDate,
                startTime=startTime,
                endTime=endTime,
                eventLocation=eventLocation,
                eventStreetAddress1=eventStreetAddress1,
                eventCity=eventCity,
                eventState=eventState,
                eventZip=eventZip,
                eventComments=eventComments,
                googleCalendarEventID=googleCalendarEventID,
            )
            db.session.add(pblEventLog)
            db.session.commit()
            return redirect(url_for("pblPlanner_bp.displayStemIIIPblPlanner"))

    return render_template(
        "pbleventeditor.html",
        title="New PBL Event Editor",
        pblEventEditorForm=pblEventEditorFormDetails,
        pblName=pblName,
        event_quarter=event_quarter,
    )
Esempio n. 4
0
def displayStemIIITeams():
    printLogEntry("Running displayStemIIITeams()")
    # Create list of students to include for PBL teams
    students = db.session.query(
        Student.firstName, Student.lastName, Student.chattStateANumber
    ).filter(Student.yearOfGraduation == getClassYearOfGraduation("Juniors"))

    # Create PblTeam for each student for each quarter
    className = "STEM III"
    academicYear = getCurrentAcademicYear()
    quarters = [1, 2, 3, 4]
    for student in students:
        for quarter in quarters:
            # Check whether PblTeam exists for student
            log = PblTeams.query.filter(
                PblTeams.className == className,
                PblTeams.academicYear == academicYear,
                PblTeams.quarter == quarter,
                PblTeams.chattStateANumber == student.chattStateANumber,
            ).first()
            # Skip the record if the student is already in the PblTeams table
            if log:
                pass
            # Add a new record if the student is not already in the PblTeams table
            else:
                schoolYear, semester = getSchoolYearAndSemester(academicYear, quarter)
                pblTeam = PblTeams(
                    className=className,
                    academicYear=academicYear,
                    schoolYear=schoolYear,
                    semester=semester,
                    quarter=quarter,
                    pblNumber=quarter,
                    pblTeamNumber=0,
                    chattStateANumber=student.chattStateANumber,
                    pbl_id=None,
                )
                db.session.add(pblTeam)
                db.session.commit()
                print(
                    "Adding new PBL Team for",
                    student.firstName,
                    student.lastName,
                    student.chattStateANumber,
                )
    # Check request.method for different scenarios:
    # Default: GET with no parameters will display PBL team based on computed current quarter
    # POST with request.form handles case when user changes quarter using dropdown menu
    # GET with selectedQuarter handles case when redirected from saving team in order to stay
    # on previous page
    # The team event list uses eventCategory so it must be set to a default value if not included
    if request.method == "GET" and request.args.get("selectedQuarter"):
        quarter = request.args.get("selectedQuarter")
        print("selectedQuarter =", quarter)
        quarter = int(quarter)
        if request.args.get("selectedEventCategory"):
            eventCategory = request.args.get("selectedEventCategory")
            print("selectedEventCategory =", eventCategory)
        else:
            eventCategory = "Kickoff"
    elif request.method == "POST":
        print(request.form)
        selectedQuarter = request.form["selectedQuarter"]
        print("selectedQuarter =", selectedQuarter)
        quarter = int(selectedQuarter)
        try:
            if request.form["selectedEventCategory"]:
                eventCategory = request.form["selectedEventCategory"]
        except:
            eventCategory = "Kickoff"
    else:
        quarter = getCurrentQuarter()
        eventCategory = "Kickoff"
    pblTeams = (
        PblTeams.query.outerjoin(Pbls)
        .join(Student)
        .filter(
            PblTeams.className == className,
            PblTeams.academicYear == academicYear,
            PblTeams.quarter == quarter,
        )
        .order_by(Pbls.pblName, PblTeams.pblTeamNumber, Student.lastName)
        .all()
    )

    # Create set of numbered teams to assign students
    teamNumbers = []
    for i in range(1, 31, 1):
        teamNumbers.append(f"{i}")

    # Create tuple of pblOptions and set default choice to None
    pblOptions = list(getPblOptionsTuple(academicYear, quarter))
    pblOptions.insert(0, ("", "Choose PBL..."))
    pblOptions = tuple(pblOptions)

    # Create choices for PBL Team Communications Center
    pblEmailRecipientChoices = getPblEmailRecipientChoices(
        academicYear, quarter, className
    )
    pblCommunicationsActions = getPblEmailTemplates()

    print(pblOptions)
    quarterOptions = getQuarterChoices()
    eventCategoryChoices = getPblEventCategoryChoices()

    # Get list of PBL students and event info to display for PBL Team Event List
    pblTeamsAndEvents = (
        db.session.query(PblTeams, PblEvents)
        .select_from(PblTeams)
        .outerjoin(Pbls)
        .outerjoin(Pbls.PblEvents)
        .join(Student)
        .filter(Pbls.quarter == quarter, PblEvents.eventCategory == eventCategory)
        .order_by(
            Pbls.quarter,
            PblEvents.eventDate,
            PblEvents.startTime,
            Pbls.pblName,
            PblTeams.pblTeamNumber,
            Student.lastName,
        )
    )

    return render_template(
        "pblteams.html",
        title="STEM III Team Manager",
        students=students,
        teamNumbers=teamNumbers,
        pblOptions=pblOptions,
        pblTeams=pblTeams,
        quarterOptions=quarterOptions,
        displayQuarter=quarter,
        pblEmailRecipientChoices=pblEmailRecipientChoices,
        pblEmailTemplates=pblCommunicationsActions,
        eventCategoryChoices=eventCategoryChoices,
        displayEventCategory=eventCategory,
        pblTeamsAndEvents=pblTeamsAndEvents,
    )