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
36 changes: 9 additions & 27 deletions app/controllers/admin_routes/manageDepartments.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

from app.logic.manageDepartments import *


from playhouse.shortcuts import model_to_dict

@admin.route('/admin/manageDepartments/', methods=['GET'])
def manageDepartments(academicYear = None):
"""
Returns the Manage Departments page, which allows the admin to view all the departments
and their allocations.
"""

# Checking Admin Rights
currentUser = require_login()
if not currentUser: # If the current user is not logged in
Expand All @@ -36,42 +35,25 @@ def manageDepartments(academicYear = None):
elif currentUser.supervisor:
return render_template('errors/403.html'), 403


# The condition below may be deleted if the routing to the Manage Departments page is changed.
if academicYear == None:
academicYear = g.openTerm.termCode
else:
academicYear = int(academicYear)


currentAY, nextAY = generateAdjacentYears(academicYear)
chosenAY = Term.get(Term.termCode == academicYear)

breakHoursByDepartment = {row["department"]: str(row["totalHours"] or 0) for row in getUsedBreakHours(chosenAY)}

activeDepartments = getActiveDepartmentsWithAllocation(chosenAY)
inactiveDepartments = Department.select().where(Department.isActive == False)
currentAY, nextAY = generateAdjacentYears(g.openTerm.termCode)

allocationStatus = {
department.departmentID: getAllocationStatus(chosenAY, department)
for department in activeDepartments
}
inactiveDepartments = Department.select().where(Department.isActive == False)
allSupervisors = Supervisor.select().order_by(Supervisor.LAST_NAME)

allSupervisors= Supervisor.select().order_by(Supervisor.LAST_NAME)
breakHoursByDepartment = {row["department"]: str(row["totalHours"] or 0) for row in getUsedBreakHours(currentAY)}

activeDepartmentsAllocations = getActiveDepartmentsAllocations(currentAY,nextAY)

return render_template( 'admin/manageDepartments.html',
activeDepartments = activeDepartments,
activeDepartmentsAllocations = activeDepartmentsAllocations,
inactiveDepartments = inactiveDepartments,
allSupervisors = allSupervisors,
allSupervisors = allSupervisors,
currentAY = currentAY,
nextAY = nextAY,
academicYear = chosenAY.termName,
breakHoursByDepartment = breakHoursByDepartment,
allocationStatus = allocationStatus
)



@admin.route('/admin/complianceStatus', methods=['POST'])
def complianceStatusCheck():
"""
Expand Down
68 changes: 51 additions & 17 deletions app/logic/manageDepartments.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

from app.login_manager import require_login

from playhouse.shortcuts import model_to_dict



def generateAdjacentYears(academicYearTermCode=None):
"""
Generates the current, the previous, and the following academic years.
Generates the current, and the following academic years.
"""

currentYear = g.openTerm.termCode // 100
nextYear = currentYear + 1


currentAYCode = currentYear * 100
nextAYCode = nextYear * 100

Expand Down Expand Up @@ -50,9 +50,6 @@ def generateAdjacentYears(academicYearTermCode=None):
# Everything below this line will eventually be deleted





def getUsedBreakHours(term):
"""
Returns the total number of break hours used by each department for a given term.
Expand Down Expand Up @@ -109,7 +106,7 @@ def getLSFCountSecondaries(currentTerm, department):



def getActiveDepartmentsWithAllocation(term):
def getActiveDepartmentsWithAllocation(term,isFinal = True):
"""
Returns a list of active departments with allocations for the given term.
"""
Expand All @@ -118,24 +115,61 @@ def getActiveDepartmentsWithAllocation(term):
# activeDepartments = Department.select().where(Department.isActive == True)
# allAllocations = Allocation.select().where(Allocation.termCode == currentAY)

activeDepartments = (Department
activeDepartments = (Allocation
.select(Department, Allocation)
.join(Allocation)
.join(Department)
.where(
Department.isActive == True,
Allocation.termCode == term.termCode
)
Allocation.termCode == term.termCode,
Allocation.isFinal == isFinal,
)
)

for dept in activeDepartments:
dept.totalPrimaries = (dept.allocation.primary_10 + dept.allocation.primary_12 + dept.allocation.primary_15 + dept.allocation.primary_20)
dept.totalSecondaries = (dept.allocation.secondary_5 + dept.allocation.secondary_10)

for allocation in activeDepartments:
allocation.totalPrimaries = (allocation.primary_10 + allocation.primary_12 + allocation.primary_15 + allocation.primary_20)
allocation.totalSecondaries = (allocation.secondary_5 + allocation.secondary_10)

if isFinal: # do not need to count them for requested allocations
allocation.lsfCountPrimaries = getLSFCountPrimaries(term, allocation.department)
allocation.lsfCountSecondaries = getLSFCountSecondaries(term, allocation.department)

return activeDepartments

dept.lsfCountPrimaries = getLSFCountPrimaries(term, dept)
dept.lsfCountSecondaries = getLSFCountSecondaries(term, dept)

return activeDepartments
def getActiveDepartmentsAllocations(term,nextTerm):
"""
This function gets active departments, active allocations for the current AY and future AY.
It returns a dictionary which contains three objects grouped by the departmentID
"""

activeDepartments = Department.select().where(Department.isActive == True)

allocations = getActiveDepartmentsWithAllocation(term)

allocByDeptId = {}

# index allocations by department ID
for alloc in allocations:
allocByDeptId[alloc.department.departmentID] = alloc

requestedAllocations = getActiveDepartmentsWithAllocation(nextTerm, False)

# index requested allocations by department ID
reqAllocByDeptId = {}
for alloc in requestedAllocations:
reqAllocByDeptId[alloc.department.departmentID] = alloc

# build combined dictionary for active departments
activeDepartmentsAllocations = {}

for dept in activeDepartments:
activeDepartmentsAllocations[dept.departmentID] = {
"department": dept,
"allocation": allocByDeptId.get(dept.departmentID), # None if no allocation
"requestedAllocation": reqAllocByDeptId.get(dept.departmentID), # None if no requested allocation
}
return activeDepartmentsAllocations


def getAllocationStatus(term, department):
Expand Down
71 changes: 44 additions & 27 deletions app/templates/admin/manageDepartments.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,69 +91,79 @@ <h1>Manage Departments</h1>
<thead>
<tr>
<th>Department</th>

<th>Status</th>
<th>Current Allocations <br>({{ academicYear }})</th>
<th>Current Allocations <br>({{ currentAY.termName }})</th>
<th>Requested Allocations <br>({{ nextAY.termName }})</th>
<th class="noSorting">Actions</th>
</tr>
</thead>
<tbody>
{% for department in activeDepartments %}
{% for entry in activeDepartmentsAllocations.values() %}

<tr>
<td scope="row">
<a href="/department/{{ department.ORG }}/{{ department.ACCOUNT }}" class="departmentName"
id="{{department.departmentID}}">{{department.DEPT_NAME}}</a><br><small>({{department.ORG}},
{{department.ACCOUNT}})</small>
<a href="/department/{{ entry.department.ORG }}/{{ entry.department.ACCOUNT }}" class="departmentName"
id="{{entry.department.departmentID}}">{{entry.department.DEPT_NAME}}</a><br><small>({{entry.department.ORG}},
{{entry.department.ACCOUNT}})</small>
</td>
<td id="dept_{{department.departmentID}}" scope="row" style="text-align: center; vertical-align: middle"
data-order="{% if department.departmentCompliance == True %}1{% else %}-1{% endif %}">
<button type="button" id="dept_btn_{{department.departmentID}}" name="deptName"
class="{% if department.departmentCompliance == True %} btn btn-success {% else %} btn btn-danger {% endif %} complianceBtn"
onclick="status({{department.departmentID}}, '{{department.DEPT_NAME}}')"
value="{{department.departmentID}}">
{% if department.departmentCompliance == True %}In

<td id="dept_{{entry.department.departmentID}}" scope="row"
style="text-align: center; vertical-align: middle"
data-order="{% if entry.department.departmentCompliance == True %}1{% else %}-1{% endif %}">
<button type="button" id="dept_btn_{{entry.department.departmentID}}" name="deptName"
class="{% if entry.department.departmentCompliance == True %} btn btn-success {% else %} btn btn-danger {% endif %} complianceBtn"
onclick="status({{entry.department.departmentID}}, '{{entry.department.DEPT_NAME}}')"
value="{{entry.department.departmentID}}">
{% if entry.department.departmentCompliance == True %}In
Compliance{% else %}Not in Compliance{% endif %}
</button>
</td>

<td style="white-space: nowrap">
{% if entry.allocation %}
<span>
<strong>Primary: </strong>
{{department.lsfCountPrimaries}} of {{department.totalPrimaries}}
{{entry.allocation.lsfCountPrimaries}} of {{entry.allocation.totalPrimaries}}
</span>
<br>

<span>
<strong>Secondary:</strong>
{{department.lsfCountSecondaries}} of {{department.totalSecondaries}}
{{entry.allocation.lsfCountSecondaries}} of {{entry.allocation.totalSecondaries}}
</span>
<br>
<span>
<strong>Break:</strong> {{ breakHoursByDepartment.get(department.departmentID, 0) }} of {{
department.allocation.breakHours }} hours
<strong>Break:</strong> {{ breakHoursByDepartment.get(entry.department.departmentID, 0) }} of
{{entry.allocation.breakHours }} hours
</span>
{% else %}
<span class="text-muted">No current allocation</span>
{% endif %}

</td>


<td style="white-space: nowrap">
{% if entry.allocation %}
<span>
<strong>Primary: </strong>
{{department.lsfCountPrimaries}} of {{department.totalPrimaries}}
{{entry.requestedAllocation.totalPrimaries}}
</span>
<br>
<span>
<strong>Secondary:</strong>
{{department.lsfCountSecondaries}} of {{department.totalSecondaries}}
{{entry.requestedAllocation.totalSecondaries}}
</span>
<br>
<span>
<strong>Break:</strong> {{ breakHoursByDepartment.get(department.departmentID, 0) }} of {{ department.allocation.breakHours }} hours
<strong>Break:</strong> {{ entry.requestedAllocation.breakHours }} hours
</span>
{% else %}
<span class="text-muted">No current allocation</span>
{% endif %}

</td>



<td style="white-space: nowrap">
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1"
Expand All @@ -162,19 +172,26 @@ <h1>Manage Departments</h1>
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu1">
<li><a href="/department/{{department.ORG}}/{{department.ACCOUNT}}/allocations">Show Allocation
<li><a href="/department/{{entry.department.ORG}}/{{entry.department.ACCOUNT}}/allocations">Show
Allocation
History</a></li>
<li><a href="/department/{{department.ORG}}/{{department.ACCOUNT}}/members">Manage Dept Members</a>
<li><a href="/department/{{entry.department.ORG}}/{{entry.department.ACCOUNT}}/members">Manage Dept
Members</a>
</li>
<li><a href="/department/{{department.ORG}}/{{department.ACCOUNT}}/positions">View Positions</a>
<li><a href="/department/{{entry.department.ORG}}/{{entry.department.ACCOUNT}}/positions">View
Positions</a>
</li>
<li><a href="{{department.ORG}}/{{department.ACCOUNT}}/allocationReview">Review Allocation</a></li>
<li><a href="{{entry.department.ORG}}/{{entry.department.ACCOUNT}}/allocationReview">Review
Allocation</a></li>
</ul>


</div>
</div>

</td>
</tr>
{% endfor %}
{%endfor%}
</tbody>
</table>
</div>
Expand Down
Loading