コード例 #1
0
ファイル: routes.py プロジェクト: TerraX3000/P2MT
def displayStemIIIPblPlanner():
    printLogEntry("Running displayStemIIIPblPlanner()")
    pbls = Pbls.query.order_by(
        Pbls.schoolYear.desc(), Pbls.quarter.desc(), Pbls.pblName
    )

    pblEvents = (
        PblEvents.query.join(Pbls)
        .filter(Pbls.quarter >= 0)
        .order_by(
            Pbls.quarter.desc(), PblEvents.eventDate, PblEvents.startTime, Pbls.pblName,
        )
    )

    quarterOptions = getQuarterChoices()
    currentQuarter = getCurrentQuarter()

    if request.method == "GET" and request.args.get("selectedQuarter"):
        quarter = request.args.get("selectedQuarter")
        print("selectedQuarter =", quarter)
        quarter = int(quarter)
    elif request.method == "POST":
        quarter = request.form["selectedQuarter"]
        print("selectedQuarter =", quarter)
        quarter = int(quarter)
    else:
        quarter = getCurrentQuarter()

    # Get list of kickoff and final PBL events for current year and selected quarter
    academicYear = getCurrentAcademicYear()
    pblKickoffEvents = (
        PblEvents.query.join(Pbls)
        .filter(
            PblEvents.eventCategory == "Kickoff",
            Pbls.academicYear == academicYear,
            Pbls.quarter == quarter,
        )
        .order_by(PblEvents.eventDate, PblEvents.startTime, Pbls.pblName,)
    )

    pblFinalEvents = (
        PblEvents.query.join(Pbls)
        .filter(
            PblEvents.eventCategory == "Final",
            Pbls.academicYear == academicYear,
            Pbls.quarter == quarter,
        )
        .order_by(PblEvents.eventDate, PblEvents.startTime, Pbls.pblName,)
    )

    return render_template(
        "pblplanner.html",
        title="STEM III PBL Planner",
        pbls=pbls,
        pblEvents=pblEvents,
        quarterOptions=quarterOptions,
        displayQuarter=quarter,
        pblKickoffEvents=pblKickoffEvents,
        pblFinalEvents=pblFinalEvents,
    )
コード例 #2
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,
    )
コード例 #3
0
def edit_Pbl(log_id):
    printLogEntry("Running edit_Pbl()")
    pblEditorFormDetails = pblEditorForm()
    pblEditorFormDetails.className.choices = [("STEM III", "STEM III")]
    pblEditorFormDetails.schoolYear.choices = getSchoolYearChoices()
    pblEditorFormDetails.academicYear.choices = getAcademicYearChoices()
    pblEditorFormDetails.semester.choices = getSemesterChoices()
    quarterChoices = list(getQuarterChoices())
    quarterChoices.insert(0, (0, "TBD"))
    quarterChoices = tuple(quarterChoices)
    pblEditorFormDetails.quarter.choices = quarterChoices
    # pblEditorFormDetails.pblName.choices = getPblOptionsTuple(2)

    log = Pbls.query.get_or_404(log_id)
    LogDetails = f"{(log_id)} {log.pblName}"
    printLogEntry("Running edit_Pbl(" + LogDetails + ")")

    if "submitEditPbl" in request.form:
        print("request.form", request.form)
        if not pblEditorFormDetails.validate_on_submit():
            print("Edit PBL Form errors")
            printFormErrors(pblEditorFormDetails)
        if pblEditorFormDetails.validate_on_submit():
            print("submitEditPbl submitted")

            # Update the database with the values submitted in the form
            log.className = pblEditorFormDetails.className.data
            # Check whether the PBL academic year has changed
            newAcademicYear = False
            if log.academicYear != pblEditorFormDetails.academicYear.data:
                newAcademicYear = True
            log.academicYear = pblEditorFormDetails.academicYear.data
            # Check whether the PBL quarter has changed
            newQuarter = False
            if log.quarter != pblEditorFormDetails.quarter.data:
                newQuarter = True
            log.quarter = pblEditorFormDetails.quarter.data
            log.schoolYear, log.semester = getSchoolYearAndSemester(
                log.academicYear, log.quarter
            )
            log.pblNumber = log.quarter
            log.pblName = pblEditorFormDetails.pblName.data
            log.pblSponsor = pblEditorFormDetails.pblSponsor.data
            log.pblSponsorPersonName = pblEditorFormDetails.pblSponsorPersonName.data
            log.pblSponsorPhone = pblEditorFormDetails.pblSponsorPhone.data
            log.pblSponsorEmail = pblEditorFormDetails.pblSponsorEmail.data
            log.pblComments = pblEditorFormDetails.pblComments.data
            # If the PBL year or quarter has been updated, check whether
            # the change impacts any PBL teams and remove the PBL from
            # impacted teams if necessary
            if newAcademicYear or newQuarter:
                impactedPblTeams = PblTeams.query.filter(PblTeams.pbl_id == log_id)
                for pblTeam in impactedPblTeams:
                    pblTeam.pbl_id = None
                    print(
                        f"PBL year or quarter has changed.  Removing PBL {log_id} from PBL Team {pblTeam.id}"
                    )
            db.session.commit()
            return redirect(url_for("pblPlanner_bp.displayStemIIIPblPlanner"))

    pblName = log.pblName
    print("pblName =", pblName)
    if log:
        pblEditorFormDetails.log_id.data = log.id
        pblEditorFormDetails.className.data = log.className
        pblEditorFormDetails.schoolYear.data = log.schoolYear
        pblEditorFormDetails.academicYear.data = log.academicYear
        pblEditorFormDetails.semester.data = log.semester
        pblEditorFormDetails.quarter.data = log.quarter
        pblEditorFormDetails.pblName.data = log.pblName
        pblEditorFormDetails.pblSponsor.data = log.pblSponsor
        pblEditorFormDetails.pblSponsorPersonName.data = log.pblSponsorPersonName
        pblEditorFormDetails.pblSponsorPhone.data = log.pblSponsorPhone
        pblEditorFormDetails.pblSponsorEmail.data = log.pblSponsorEmail
        pblEditorFormDetails.pblComments.data = log.pblComments
        print(
            "editPblDetails=",
            pblEditorFormDetails.log_id.data,
            pblEditorFormDetails.pblName.data,
        )
    return render_template(
        "pbleditor.html",
        title="PBL Editor",
        pblEditorForm=pblEditorFormDetails,
        pblName=pblName,
    )
コード例 #4
0
def new_Pbl():
    printLogEntry("Running new_Pbl()")
    pblEditorFormDetails = pblEditorForm(academicYear=getCurrentAcademicYear())
    pblEditorFormDetails.className.choices = [("STEM III", "STEM III")]
    pblEditorFormDetails.schoolYear.choices = getSchoolYearChoices()
    pblEditorFormDetails.academicYear.choices = getAcademicYearChoices()
    pblEditorFormDetails.semester.choices = getSemesterChoices()
    quarterChoices = list(getQuarterChoices())
    quarterChoices.insert(0, (0, "TBD"))
    quarterChoices = tuple(quarterChoices)
    pblEditorFormDetails.quarter.choices = quarterChoices
    pblEditorFormDetails.log_id.data = 0

    if "submitEditPbl" in request.form:
        print("request.form", request.form)
        if not pblEditorFormDetails.validate_on_submit():
            print("Edit PBL Form errors")
            printFormErrors(pblEditorFormDetails)
        if pblEditorFormDetails.validate_on_submit():
            print("submitEditPbl submitted")

            # Update the database with the values submitted in the form
            className = pblEditorFormDetails.className.data
            academicYear = pblEditorFormDetails.academicYear.data
            schoolYear = pblEditorFormDetails.schoolYear.data
            semester = pblEditorFormDetails.semester.data
            quarter = pblEditorFormDetails.quarter.data
            schoolYear, semester = getSchoolYearAndSemester(academicYear, quarter)
            pblName = pblEditorFormDetails.pblName.data
            pblSponsor = pblEditorFormDetails.pblSponsor.data
            pblSponsorPersonName = pblEditorFormDetails.pblSponsorPersonName.data
            pblSponsorEmail = pblEditorFormDetails.pblSponsorEmail.data
            pblSponsorPhone = pblEditorFormDetails.pblSponsorPhone.data
            pblComments = pblEditorFormDetails.pblComments.data

            pblLog = Pbls(
                className=className,
                schoolYear=schoolYear,
                academicYear=academicYear,
                semester=semester,
                quarter=quarter,
                pblNumber=quarter,
                pblName=pblName,
                pblSponsor=pblSponsor,
                pblSponsorPersonName=pblSponsorPersonName,
                pblSponsorEmail=pblSponsorEmail,
                pblSponsorPhone=pblSponsorPhone,
                pblComments=pblComments,
            )
            db.session.add(pblLog)
            db.session.commit()

            # Use id for PBL record to create placeholder kickoff and final events
            pblEventLog = PblEvents(
                pbl_id=pblLog.id,
                eventCategory="Kickoff",
                confirmed=0,
                startTime=time(hour=9, minute=30, second=0),
                endTime=time(hour=10, minute=30, second=0),
                eventCity="Chattanooga",
                eventState="TN",
            )
            db.session.add(pblEventLog)
            db.session.commit()
            pblEventLog = PblEvents(
                pbl_id=pblLog.id,
                eventCategory="Final",
                confirmed=0,
                startTime=time(hour=9, minute=30, second=0),
                endTime=time(hour=10, minute=30, second=0),
                eventCity="Chattanooga",
                eventState="TN",
            )
            db.session.add(pblEventLog)
            db.session.commit()
            flash("New PBL created!", "success")
            return redirect(url_for("pblPlanner_bp.displayStemIIIPblPlanner"))

    return render_template(
        "pbleditor.html",
        title="New PBL Editor",
        pblEditorForm=pblEditorFormDetails,
        pblName=None,
    )
コード例 #5
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,
    )