Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/admin_routes/adminManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def manageLaborAdmin():

def addAdmin(user, adminType):
setattr(user, f"is{adminType}Admin", True)
user.save()
user.save()

def removeAdmin(user, adminType):
setattr(user, f"is{adminType}Admin", False)
Expand Down
30 changes: 11 additions & 19 deletions app/controllers/main_routes/laborStatusForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from app.controllers.main_routes import *
from app.login_manager import require_login
from app.models.user import *
from app.models import mainDB
from app.models.status import *
from app.models.laborStatusForm import *
from app.models.overloadForm import *
Expand Down Expand Up @@ -73,31 +74,22 @@ def userInsert():
rspFunctional = json.loads(rsp)
all_forms = []
for i in range(len(rspFunctional)):

# Get a student record for the given bnumber
try:
student = getOrCreateStudentRecord(bnumber=rspFunctional[i]['stuBNumber'])
supervisor = createSupervisorFromTracy(bnumber=rspFunctional[i]['stuSupervisorID'])
except InvalidUserException as e:
print(e)
return "", 500

department, created = Department.get_or_create(DEPT_NAME = rspFunctional[i]['stuDepartment'])
term, created = Term.get_or_create(termCode = rspFunctional[i]['stuTermCode'])
try:
lsf = createLaborStatusForm(student, supervisor.ID, department.departmentID, term, rspFunctional[i])
createOverloadFormAndFormHistory(rspFunctional[i], lsf, currentUser, host=request.host)
try:
with mainDB.atomic():
# Get a student record for the given bnumber
student = getOrCreateStudentRecord(bnumber=rspFunctional[i]['stuBNumber'])
supervisor = createSupervisorFromTracy(bnumber=rspFunctional[i]['stuSupervisorID'])
department, created = Department.get_or_create(DEPT_NAME = rspFunctional[i]['stuDepartment'])
term, created = Term.get_or_create(termCode = rspFunctional[i]['stuTermCode'])
lsf = createLaborStatusForm(student, supervisor.ID, department.departmentID, term, rspFunctional[i])
createOverloadFormAndFormHistory(rspFunctional[i], lsf, currentUser, host=request.host)
emailDuringBreak(checkForSecondLSFBreak(term.termCode, student.ID), term)
except Exception as e:
print("Error when sending emails during break: " + str(e))


all_forms.append(True)
except Exception as e:
print("ERROR on creating Labor Status Form/Overload Form" + str(e))
all_forms.append(False)
print("ERROR on creating Labor Status Form/Overload Form" + str(e))

flash("Form(s) submitted successfully! They will be eligible for approval in one business day.", "success")
return jsonify(all_forms)

@main_bp.route("/laborstatusform/getDate/<termcode>", methods=['GET'])
Expand Down
1 change: 0 additions & 1 deletion app/logic/emailHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import os
from datetime import datetime, date


class emailHandler():
def __init__(self, formHistoryKey):
self.mail = Mail(app)
Expand Down
85 changes: 46 additions & 39 deletions app/logic/statusFormFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,41 +57,43 @@ def createOverloadFormAndFormHistory(rspFunctional, lsf, creatorID, host=None):
"""
# We create a 'Labor Status Form' first, then we check to see if a 'Labor Overload Form'
# needs to be created
isOverload = rspFunctional.get("isItOverloadForm") == "True"
if isOverload:
newLaborOverloadForm = OverloadForm.create( studentOverloadReason = None,
financialAidApproved = None,
financialAidApprover = None,
financialAidReviewDate = None,
SAASApproved = None,
SAASApprover = None,
SAASReviewDate = None,
laborApproved = None,
laborApprover = None,
laborReviewDate = None)
formOverload = FormHistory.create( formID = lsf.laborStatusFormID,
historyType = "Labor Overload Form",
overloadForm = newLaborOverloadForm.overloadFormID,
createdBy = creatorID,
createdDate = date.today(),
status = "Pre-Student Approval")
email = emailHandler(formOverload.formHistoryID)
link = makeThirdPartyLink("student", host, formOverload.formHistoryID)
email.LaborOverLoadFormSubmitted(link)

formHistory = FormHistory.create( formID = lsf.laborStatusFormID,
historyType = "Labor Status Form",
overloadForm = None,
createdBy = creatorID,
createdDate = date.today(),
status = "Pre-Student Approval")
try:
isOverload = rspFunctional.get("isItOverloadForm") == "True"
if isOverload:
newLaborOverloadForm = OverloadForm.create( studentOverloadReason = None,
financialAidApproved = None,
financialAidApprover = None,
financialAidReviewDate = None,
SAASApproved = None,
SAASApprover = None,
SAASReviewDate = None,
laborApproved = None,
laborApprover = None,
laborReviewDate = None)
formOverload = FormHistory.create( formID = lsf.laborStatusFormID,
historyType = "Labor Overload Form",
overloadForm = newLaborOverloadForm.overloadFormID,
createdBy = creatorID,
createdDate = date.today(),
status = "Pre-Student Approval")
email = emailHandler(formOverload.formHistoryID)
link = makeThirdPartyLink("student", host, formOverload.formHistoryID)
email.LaborOverLoadFormSubmitted(link)

if not formHistory.formID.termCode.isBreak and not isOverload:
email = emailHandler(formHistory.formHistoryID)
email.laborStatusFormSubmitted()
Comment thread
Kafui123 marked this conversation as resolved.
formHistory = FormHistory.create( formID = lsf.laborStatusFormID,
historyType = "Labor Status Form",
overloadForm = None,
createdBy = creatorID,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the email.laborStatusFormSubmitted be here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the call is intentionally handled later in the flow. For overload forms, the email is triggered earlier on line 81 via email.LaborOverloadFormSubmitted(link) and for regular status forms, the emaila gets sent on line 91 after the FormHistory record is created.

createdDate = date.today(),
status = "Pre-Student Approval")

return formHistory
if not formHistory.formID.termCode.isBreak and not isOverload:
email = emailHandler(formHistory.formHistoryID)

return formHistory
except Exception as e:
print("Error creating overload form:", e)
raise


def checkForSecondLSFBreak(termCode, student):
Expand Down Expand Up @@ -223,13 +225,18 @@ def emailDuringBreak(secondLSFBreak, term):
"""
Sending emails during break period
"""
if term.isBreak:
isOneLSF = json.loads(secondLSFBreak)
formHistory = FormHistory.get(FormHistory.formHistoryID == isOneLSF['formHistoryID'])
email = emailHandler(formHistory.formHistoryID)
email.laborStatusFormSubmitted()
if(len(isOneLSF["previousSupervisorNames"]) > 1): #Student has more than one lsf. Send email to both supervisors and student
email.notifyAdditionalLaborStatusFormSubmittedForBreak()
try:
if term.isBreak:
isOneLSF = json.loads(secondLSFBreak)
formHistory = FormHistory.get(FormHistory.formHistoryID == isOneLSF['formHistoryID'])
email = emailHandler(formHistory.formHistoryID)
email.laborStatusFormSubmitted()
if(len(isOneLSF["previousSupervisorNames"]) > 1): #Student has more than one lsf. Send email to both supervisors and student
email.notifyAdditionalLaborStatusFormSubmittedForBreak()
except Exception as e:
print("Error sending email during break:", e)
raise



def createOverloadForm(newWeeklyHours, lsf, currentUser, adjustedForm=None, formHistories=None, host=None):
Expand Down
5 changes: 3 additions & 2 deletions app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from app import app
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I know the rationale for this as working on init.py file affect most of the backend

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these lines to resolve a circular import issue where other files depended on the db instance from this file. At the time, those modules were being imported before the database had been properly initialized, which led to errors when accessing db. Importing the Flask app and initializing db with it ensured that the database instance was available when those modules were loaded.

import os

from peewee import *
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy(app)

from app import app

def getMySQLDB():
if os.environ.get("USING_CONTAINER", False):
Expand Down
Loading