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: 0 additions & 2 deletions app/controllers/admin_routes/adminManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from flask import Flask, redirect, url_for, flash, jsonify
from app.models.supervisor import Supervisor
from app.models.student import Student
from app.logic.tracy import Tracy
from app.logic.userInsertFunctions import createStudentFromTracy, createSupervisorFromTracy, createUser
from app.logic.adminManagement import searchForAdmin, getUser
from app.logic.utils import adminFlashMessage

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin_routes/allPendingForms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
from app.models.formHistory import FormHistory
from app.models.term import Term
from app.logic.banner import Banner
from app.logic.tracy import Tracy
from app.models.Tracy.stuposn import STUPOSN
from app.models.supervisor import Supervisor
from app.models.student import Student
from app.models.historyType import HistoryType
Expand Down
1 change: 0 additions & 1 deletion app/controllers/admin_routes/manage_departments.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from flask import request, redirect
from flask import jsonify
from playhouse.shortcuts import model_to_dict
from app.logic.tracy import Tracy

@admin.route('/admin/manageDepartments', methods=['GET'])
# @login_required
Expand Down
34 changes: 25 additions & 9 deletions app/controllers/main_routes/alterLSF.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from app.models.formHistory import FormHistory
from app.models.user import User
from app.models.supervisor import Supervisor
from app.logic.userInsertFunctions import createSupervisorFromTracy
from app.logic.emailHandler import *
from app.login_manager import require_login
from app.logic.tracy import Tracy, InvalidQueryException
Expand All @@ -27,7 +26,6 @@ def alterLSF(laborStatusKey):
if not currentUser.isLaborAdmin: # Not an admin
if currentUser.student and not currentUser.supervisor: # If a student is logged in and trying to get to this URL then send them back to their own page.
return redirect("/laborHistory/" + currentUser.student.ID)

currentDate = date.today()
#If logged in....
#Step 1: get form attached to the student (via labor history modal)
Expand All @@ -37,7 +35,6 @@ def alterLSF(laborStatusKey):

# Query the status of the form to determine if correction or adjust LSF
formStatus = (FormHistory.get(FormHistory.formID == laborStatusKey).status_id)

if currentDate > form.termCode.adjustmentCutOff and formStatus == "Approved" and not currentUser.isLaborAdmin:
return render_template("errors/403.html")
#Step 2: get prefill data from said form, then the data that populates dropdowns for supervisors and position
Expand All @@ -60,12 +57,21 @@ def alterLSF(laborStatusKey):
totalHours += i.weeklyHours
else:
prefillhours = form.contractHours

#These are the data fields to populate our dropdowns(Supervisor. Position)
supervisors = Tracy().getSupervisors()
positions = Tracy().getPositionsFromDepartment(form.department.ORG, form.department.ACCOUNT)
departments = Tracy().getDepartments()

supervisors = Supervisor.select() #.where(Supervisor.isActive) if we want supervisors to be active one
positions = (
LaborStatusForm
.select(FormHistory, LaborStatusForm, Department)
.join(FormHistory, on=(FormHistory.formID == LaborStatusForm.laborStatusFormID))
.switch(LaborStatusForm)
.join(Department, on=(LaborStatusForm.department == Department.departmentID))
.where(
(Department.ACCOUNT == form.department.ACCOUNT) &
(Department.ORG == form.department.ORG)
)
)
positions = {position for position in positions}
departments = Department.select()
# supervisors from the old system WILL have a Supervisor record, but might not have a Tracy record
oldSupervisor = Supervisor.get_or_none(ID = form.supervisor.ID)
if not oldSupervisor:
Expand Down Expand Up @@ -119,7 +125,17 @@ def getDate(termcode):
@main_bp.route("/alterLSF/fetchPositions/<departmentOrg>/<departmentAccount>", methods=['GET'])
def fetchPositions(departmentOrg, departmentAccount):
currentUser = require_login()
positions = Tracy().getPositionsFromDepartment(departmentOrg, departmentAccount)
positions = (
LaborStatusForm
.select(LaborStatusForm, FormHistory, Department)
.join(FormHistory, on=(FormHistory.formID == LaborStatusForm.laborStatusFormID))
.switch(LaborStatusForm)
.join(Department, on=(LaborStatusForm.department == Department.departmentID))
.where(
(Department.ACCOUNT == departmentAccount) &
(Department.ORG == departmentOrg)
)
)
positionDict = {}
for position in positions:
if position.POSN_CODE != "S12345" or currentUser.isLaborAdmin:
Expand Down
11 changes: 9 additions & 2 deletions app/controllers/main_routes/laborHistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,16 @@ def populateModal(statusKey):
form.adjustedForm.newValue = newSupervisor.FIRST_NAME +" "+ newSupervisor.LAST_NAME

if form.adjustedForm.fieldAdjusted == "position": # if position field has been changed in adjust form then retriev position name.
newPosition = Tracy().getPositionFromCode(newValue)
newPosition = (
LaborStatusForm
.select()
.where(LaborStatusForm.POSN_CODE == newValue)
.first()
)
try:
oldPosition = Tracy().getPositionFromCode(oldValue)
oldPosition = LaborStatusForm.get_or_none(
LaborStatusForm.POSN_CODE == oldValue
)
except:
oldPosition = types.SimpleNamespace(POSN_TITLE="Unknown - " + oldValue, WLS="?")

Expand Down
25 changes: 17 additions & 8 deletions app/controllers/main_routes/laborStatusForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from app.logic.emailHandler import*
from app.logic.userInsertFunctions import*
from app.models.supervisor import Supervisor
from app.logic.tracy import Tracy
from app.controllers.main_routes.laborReleaseForm import createLaborReleaseForm
from app.logic.allPendingForms import saveStatus
from app.logic.statusFormFunctions import *
Expand All @@ -37,10 +36,10 @@ def laborStatusForm(laborStatusKey = None):
return redirect('/laborHistory/' + currentUser.student.ID)

# Logged in
students = Tracy().getStudents()
students = Student.select()
terms = Term.select().where(Term.termState == "open") # changed to term state, open, closed, inactive
staffs = Tracy().getSupervisors()
departments = Tracy().getDepartments()
staffs = Supervisor.select()
departments = Department.select()

# Only prepopulate form if current user is the supervisor or creator of the form.
if laborStatusKey != None:
Expand Down Expand Up @@ -77,7 +76,7 @@ def userInsert():
# Get a student record for the given bnumber
try:
student = getOrCreateStudentRecord(bnumber=rspFunctional[i]['stuBNumber'])
supervisor = createSupervisorFromTracy(bnumber=rspFunctional[i]['stuSupervisorID'])
supervisor = Supervisor.get(Supervisor.ID ==rspFunctional[i]['stuSupervisorID'])
except InvalidUserException as e:
print(e)
return "", 500
Expand Down Expand Up @@ -119,7 +118,17 @@ def getDates(termcode):
def getPositions(departmentOrg, departmentAcct):
""" Get all of the positions that are in the selected department """
currentUser = require_login()
positions = Tracy().getPositionsFromDepartment(departmentOrg,departmentAcct)
positions = set(
LaborStatusForm
.select(FormHistory, LaborStatusForm, Department)
.join(FormHistory, on=(FormHistory.formID == LaborStatusForm.laborStatusFormID))
.switch(LaborStatusForm)
.join(Department, on=(LaborStatusForm.department == Department.departmentID))
.where(
(Department.ACCOUNT == departmentAcct) &
(Department.ORG == departmentOrg)
)
)
positionDict = {}
for position in positions:
if position.POSN_CODE != "S12345" or currentUser.isLaborAdmin:
Expand Down Expand Up @@ -187,8 +196,8 @@ def releaseAndRehire():
createLaborReleaseForm(currentUser, previousPrimaryPosition.formID, tomorrowDate, "Satisfactory", "Released by labor admin.", "Approved", todayDate, currentUser)

# Create new labor status form
student = getOrCreateStudentRecord(bnumber=studentDict['stuBNumber'])
supervisor = createSupervisorFromTracy(bnumber=studentDict['stuSupervisorID'])
student = Student.get(Student.ID == studentDict['stuBNumber'])
supervisor = Supervisor.get(Supervisor.ID == studentDict['stuSupervisorID'])
department, created = Department.get_or_create(DEPT_NAME = studentDict['stuDepartment'])
term, created = Term.get_or_create(termCode = studentDict['stuTermCode'])

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/main_routes/search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from app.controllers.main_routes import main_bp
from app.login_manager import require_login
from app.logic.tracy import Tracy, InvalidQueryException
from app.logic.search import limitSearchByUserDepartment, studentDbToDict, usernameFromEmail
from app.models.student import Student
from app.models.laborStatusForm import LaborStatusForm
Expand Down Expand Up @@ -33,7 +32,8 @@ def search(query=None):
# bnumber search
if re.match('[Bb]\d+', query):
our_students = list(map(studentDbToDict, Student.select().where(Student.ID % "{}%".format(query.upper()))))
current_students = list(map(studentDbToDict, Tracy().getStudentsFromBNumberSearch(query)))
current_students = list(map(studentDbToDict, Student.select().where(Student.ID.contains(query))))


# name search
else:
Expand All @@ -47,7 +47,7 @@ def search(query=None):
results = Student.select().where((Student.preferred_name ** first_query | Student.legal_name ** first_query) & Student.LAST_NAME ** last_query)

our_students = list(map(studentDbToDict, results))
current_students = list(map(studentDbToDict, Tracy().getStudentsFromUserInput(query)))
current_students = list(map(studentDbToDict, Student.select().where((Student.LAST_NAME.contains(query)) | (Student.preferred_name.contains(query)) | (Student.legal_name.contains(query)))))

# combine lists, remove duplicates, and then sort
students = list({v['bnumber']:v for v in (current_students + our_students)}.values())
Expand Down
13 changes: 7 additions & 6 deletions app/logic/adminManagement.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from peewee import DoesNotExist
from app.models.user import User
from app.logic.tracy import Tracy
from flask import request, flash
from app.logic.userInsertFunctions import createStudentFromTracy, createSupervisorFromTracy, createUser

from app.models.supervisor import Supervisor
from app.models.student import Student
from app.logic.tracy import Tracy

def searchForAdmin(rsp):
userInput = rsp[1]
adminType = rsp[0]
userList = []
if adminType == "addlaborAdmin":
tracyStudents = Tracy().getStudentsFromUserInput(userInput)
databaseStudents = Student.select().where(Student.legal_name.contains(userInput) | Student.preferred_name.contains(userInput)| Student.LAST_NAME.contains(userInput))
students = []
for student in tracyStudents:
for student in databaseStudents:
try:
existingUser = User.get(User.student == student.ID)
if existingUser.isLaborAdmin:
Expand All @@ -28,9 +29,9 @@ def searchForAdmin(rsp):
'lastName': student.LAST_NAME,
'type': 'Student'
})
tracySupervisors = Tracy().getSupervisorsFromUserInput(userInput)
databaseSupervisors = Supervisor.select().where(Supervisor.legal_name.contains(userInput) | Supervisor.preferred_name.contains(userInput)| Supervisor.LAST_NAME.contains(userInput))
supervisors = []
for supervisor in tracySupervisors:
for supervisor in databaseSupervisors:
try:
existingUser = User.get(User.supervisor == supervisor.ID)
if ((existingUser.isLaborAdmin and adminType == "addlaborAdmin")
Expand Down
19 changes: 16 additions & 3 deletions app/logic/allPendingForms.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def saveStatus(new_status, formHistoryIds, currentUser):
LSF = LaborStatusForm.get_by_id(formHistory.formID)
overrideOriginalStatusFormOnAdjustmentFormApproval(formHistory, LSF)


else:
print("Unable to update form status for formHistoryID {}.".format(id))
return jsonify({"success": False}), 500
Expand Down Expand Up @@ -105,7 +106,9 @@ def overrideOriginalStatusFormOnAdjustmentFormApproval(form, LSF):

if form.adjustedForm.fieldAdjusted == "position":
LSF.POSN_CODE = form.adjustedForm.newValue
position = Tracy().getPositionFromCode(form.adjustedForm.newValue)
position = LaborStatusForm.get_or_none(
LaborStatusForm.POSN_CODE == fieldsChanged[fieldName]["newValue"]
)
LSF.POSN_TITLE = position.POSN_TITLE
LSF.WLS = position.WLS
LSF.save()
Expand Down Expand Up @@ -213,7 +216,12 @@ def modal_approval_and_denial_data(formHistoryIdList):
if formHistory.adjustedForm:
match formHistory.adjustedForm.fieldAdjusted:
case "position":
position = Tracy().getPositionFromCode(formHistory.adjustedForm.newValue)
position = (
LaborStatusForm
.select()
.where(LaborStatusForm.POSN_CODE == formHistory.adjustedForm.newValue)
.first()
)
position = position.POSN_TITLE
case "supervisor":
supervisor = Supervisor.get(Supervisor.ID == formHistory.adjustedForm.newValue)
Expand Down Expand Up @@ -276,7 +284,12 @@ def checkAdjustment(allForms):

if allForms.adjustedForm.fieldAdjusted == "position":
newPositionCode = allForms.adjustedForm.newValue
newPosition = Tracy().getPositionFromCode(newPositionCode)
newPosition = (
LaborStatusForm
.select()
.where(LaborStatusForm.POSN_CODE == newPositionCode)
.first()
)
# temporarily storing the position code and wls in new value, and position name in old value
# because we want to show these information in the hmtl template.
allForms.adjustedForm.newValue = newPosition.POSN_CODE +" (" + newPosition.WLS+")"
Expand Down
6 changes: 4 additions & 2 deletions app/logic/alterLSF.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def modifyLSF(fieldsChanged, fieldName, lsf, currentUser, host=None):
lsf.supervisorNotes = noteEntry.notesContents
lsf.save()
if fieldName == "supervisor":
supervisor = createSupervisorFromTracy(bnumber=fieldsChanged[fieldName]["newValue"])
supervisor = Supervisor.get(Supervisor.ID == fieldsChanged[fieldName]["newValue"])
lsf.supervisor = supervisor.ID
lsf.save()

Expand All @@ -31,7 +31,9 @@ def modifyLSF(fieldsChanged, fieldName, lsf, currentUser, host=None):
lsf.save()

if fieldName == "position":
position = Tracy().getPositionFromCode(fieldsChanged[fieldName]["newValue"])
position = LaborStatusForm.get_or_none(
LaborStatusForm.POSN_CODE == fieldsChanged[fieldName]["newValue"]
)
lsf.POSN_CODE = position.POSN_CODE
lsf.POSN_TITLE = position.POSN_TITLE
lsf.WLS = position.WLS
Expand Down
43 changes: 0 additions & 43 deletions app/logic/departmentPositions.py

This file was deleted.

18 changes: 13 additions & 5 deletions app/logic/emailHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from app.models.student import*
from datetime import datetime
from app.models.emailTracker import *
from app.logic.tracy import Tracy
import string
from app import app
import os
Expand Down Expand Up @@ -69,13 +68,22 @@ def __init__(self, formHistoryKey):

if self.formHistory.adjustedForm:
if self.formHistory.adjustedForm.fieldAdjusted == "supervisor":
from app.logic.userInsertFunctions import createSupervisorFromTracy
newSupervisor = createSupervisorFromTracy(bnumber=self.formHistory.adjustedForm.newValue)
newSupervisor = Supervisor.select().where(Supervisor.ID == self.formHistory.adjustedForm.newValue)
self.newAdjustmentField = "Pending new Supervisor: {0} {1}".format(newSupervisor.FIRST_NAME, newSupervisor.LAST_NAME)
self.oldAdjustmentField = "Current Supervisor: {0} {1}".format(self.formHistory.formID.supervisor.FIRST_NAME, self.formHistory.formID.supervisor.LAST_NAME)
elif self.formHistory.adjustedForm.fieldAdjusted == "position":
currentPosition = Tracy().getPositionFromCode(self.formHistory.adjustedForm.oldValue)
newPosition = Tracy().getPositionFromCode(self.formHistory.adjustedForm.newValue)
currentPosition = (
LaborStatusForm
.select()
.where(LaborStatusForm.POSN_CODE == self.formHistory.adjustedForm.oldValue)
.first()
)
newPosition = (
LaborStatusForm
.select()
.where(LaborStatusForm.POSN_CODE == self.formHistory.adjustedForm.newValue)
.first()
)
self.oldAdjustmentField = "Current Position: {0} ({1})".format(currentPosition.POSN_TITLE, currentPosition.WLS)
self.newAdjustmentField = "Pending new Position: {0} ({1})".format(newPosition.POSN_TITLE, newPosition.WLS)
else:
Expand Down
1 change: 0 additions & 1 deletion app/logic/statusFormFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from app.models.formHistory import*
from app.logic.emailHandler import emailHandler
from app.logic.utils import makeThirdPartyLink, calculateExpirationDate
from app.logic.tracy import Tracy, InvalidQueryException
from flask import request, json, jsonify
from functools import reduce
import operator
Expand Down
Loading