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
89 changes: 58 additions & 31 deletions app/controllers/main_routes/main_routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import render_template, request, json, redirect, url_for, send_file, g, flash, jsonify
from peewee import JOIN, DoesNotExist
from peewee import JOIN, DoesNotExist, fn
from functools import reduce
import operator
from app.models.allocation import Allocation
Expand All @@ -10,6 +10,7 @@
from app.models.laborStatusForm import LaborStatusForm
from app.models.formHistory import FormHistory
from app.models.term import Term
from app.models.allocation import Allocation
from app.controllers.admin_routes.allPendingForms import checkAdjustment
from app.controllers.main_routes import main_bp
from app.logic.download import CSVMaker, saveFormSearchResult, retrieveFormSearchResult
Expand Down Expand Up @@ -76,24 +77,70 @@ def departmentPortal(org=None,account=None):

staff = Tracy().getSupervisors()
supervisors = []
try:
allocation = Allocation.select(Allocation, Term).join(Term).where(Allocation.department == dept, Allocation.termCode == g.openTerm).get()
except DoesNotExist:
allocation = None
term = g.openTerm.termName
ViewAllocations(org, account)

for i in staff:
if i.ORG == org:
supervisors.append(i.FIRST_NAME + " " + i.LAST_NAME + " (" + i.EMAIL + ")")
return render_template('main/departmentPortal.html',

allocation = None
allocationBands = None
totalPositionsAllocated = None
totalPositionsUsed = None
breakHoursUsed = None
if dept and g.openTerm:
allocation = Allocation.get_or_none(Allocation.department == dept, Allocation.termCode == g.openTerm)
if allocation:
bandFields = [
('primary_10', 'Primary', 10),
('primary_12', 'Primary', 12),
('primary_15', 'Primary', 15),
('primary_20', 'Primary', 20),
('secondary_5', 'Secondary', 5),
('secondary_10', 'Secondary', 10),
]
allocationBands = {}
for fieldName, jobType, hours in bandFields:
used = (LaborStatusForm
.select()
.join(FormHistory, on=(FormHistory.formID == LaborStatusForm.laborStatusFormID))
.where(LaborStatusForm.department == dept,
LaborStatusForm.termCode == g.openTerm,
LaborStatusForm.jobType == jobType,
LaborStatusForm.weeklyHours == hours,
FormHistory.historyType == "Labor Status Form",
~(FormHistory.status % "Denied%"))
.distinct()
.count())
allocationBands[fieldName] = {'used': used, 'allocated': getattr(allocation, fieldName)}

totalPositionsAllocated = sum(band['allocated'] for band in allocationBands.values())
totalPositionsUsed = sum(band['used'] for band in allocationBands.values())

# Break hours are tracked on separate break-term rows (e.g. Thanksgiving Break)
# that share the same academic year prefix as the open AY term.
yearPrefix = str(g.openTerm.termCode)[:-2]
breakTermCodes = [t.termCode for t in Term.select().where(Term.isBreak == True)
if str(t.termCode).startswith(yearPrefix)]
breakHoursUsed = (LaborStatusForm
.select(fn.SUM(LaborStatusForm.contractHours))
.join(FormHistory, on=(FormHistory.formID == LaborStatusForm.laborStatusFormID))
.where(LaborStatusForm.department == dept,
LaborStatusForm.termCode.in_(breakTermCodes),
FormHistory.historyType == "Labor Status Form",
~(FormHistory.status % "Denied%"))
.scalar()) or 0

return render_template('main/departmentPortal.html',
departments = departments,
department = dept,
positions = positions,
supervisors = supervisors,
# department_name = dept.DEPT_NAME,
allocation = allocation,
term = term
)
allocationBands = allocationBands,
totalPositionsAllocated = totalPositionsAllocated,
totalPositionsUsed = totalPositionsUsed,
breakHoursUsed = breakHoursUsed,
currentTerm = g.openTerm)

@main_bp.route('/department/<org>/<account>/managepositions', methods=['GET'])
def managePositions(org, account):
Expand Down Expand Up @@ -177,24 +224,4 @@ def submitToBanner(formHistoryId):
return "Form successfully submitted to Banner.", 200
else:
return "Submitting to Banner failed.", 500

@main_bp.route('/department/<org>/<account>', methods=['GET'])
def ViewAllocations(org, account):

try:
dept = Department.get(Department.ORG == org, Department.ACCOUNT == account)
except DoesNotExist:
return render_template('errors/404.html'), 404


allocation = Allocation.select(Allocation, Term).join(Term).where(Allocation.department == dept, Allocation.termCode == g.openTerm)
print(g.openTerm, '*********************************************************')
term = g.openTerm.termName
print(term, type(term), '*********************************************************')
return render_template('main/departmentPortal.html',
department = dept,
department_name = dept.DEPT_NAME,
allocation = allocation,
term = term
)

39 changes: 23 additions & 16 deletions app/templates/main/departmentPortal.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,39 @@ <h1 style="display: inline; margin: 0;" >Allocations</h1>
</div>
<div>
<div class="header-container" style="display: flex; justify-content: space-between; align-items: center; padding-left: 10px; padding-right: 10px;">
<h3>{{ term }}</h3> <h3>15/ {{allocation.primary_10 + allocation.primary_12 + allocation.primary_15 + allocation.primary_20 + allocation.secondary_5 + allocation.secondary_10}} Positions</h3>
<h3>{{ currentTerm.termName.replace("AY", "Term") if currentTerm else "No open term" }}</h3>
<h3>{{ totalPositionsUsed if allocation else "No allocation" }}{% if allocation %}/{{ totalPositionsAllocated }}{% endif %} Positions</h3>
</div>
<div class ="allocation-list" style="display: flex; justify-content: space-between; align-items: center; padding-left: 10px; padding-right: 10px;">
<ul style="font-size: 1.2em; padding-left: 75px;">
<li>10 Hour - 2/{{allocation.primary_10}}</li>
<li>12 Hour - 3/{{allocation.primary_12}}</li>
<li>15 Hour - 5/{{allocation.primary_15}}</li>
<li>20 Hour - 5/{{allocation.primary_20}}</li>
</ul>
<ul style="font-size: 1.2em; padding-right: 75px;">
<li>5 Hour - 2/{{allocation.secondary_5}}</li>
<li>10 Hour - 3/{{allocation.secondary_10}}</li>
</ul>
{% if allocation %}
<div class ="allocation-list" style="display: flex; justify-content: space-between; align-items: flex-start; padding-left: 10px; padding-right: 10px;">
<div style="padding-left: 75px;">
<h4 style="margin: 0 0 4px 0;">Primary</h4>
<ul style="font-size: 1.2em; margin: 0; padding-left: 20px;">
<li>10 Hour - {{ allocationBands.primary_10.used }}/{{ allocationBands.primary_10.allocated }}</li>
<li>12 Hour - {{ allocationBands.primary_12.used }}/{{ allocationBands.primary_12.allocated }}</li>
<li>15 Hour - {{ allocationBands.primary_15.used }}/{{ allocationBands.primary_15.allocated }}</li>
<li>20 Hour - {{ allocationBands.primary_20.used }}/{{ allocationBands.primary_20.allocated }}</li>
</ul>
</div>
<div style="padding-right: 75px;">
<h4 style="margin: 0 0 4px 0;">Secondary</h4>
<ul style="font-size: 1.2em; margin: 0; padding-left: 20px;">
<li>5 Hour - {{ allocationBands.secondary_5.used }}/{{ allocationBands.secondary_5.allocated }}</li>
<li>10 Hour - {{ allocationBands.secondary_10.used }}/{{ allocationBands.secondary_10.allocated }}</li>
</ul>
</div>
</div>
{% endif %}
</div>
<div class="header-container" style="display: flex; justify-content: space-between; align-items: center; padding-left: 10px; padding-right: 10px;">
<h3>Break Hours</h3> <h3>0/200 Hours</h3>
<h3>Break Hours</h3>
<h3>{{ breakHoursUsed if allocation else "No allocation" }}{% if allocation %}/{{ allocation.breakHours }}{% endif %} Hours</h3>
</div>
</div>
<div class="card-footer text-center">
<a href="#" class="btn btn-primary btn-m">
Manage Allocations <span class="glyphicon glyphicon-chevron-right"></span>
</a>
<a href="#" class="btn btn-primary btn-m">
Request Allocation <span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</section>

Expand Down
Loading