Skip to content
2 changes: 2 additions & 0 deletions app/config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ support_email_contact: "support@bereacollege.onmicrosoft.com"
show_queries: True
test_entry: "Default"

lsf_url: "REPLACE"

db:
name: "celts"
host: "db"
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/minor/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def viewCceMinor(username):
"""
Load minor management page with community engagements and summer experience
"""
if not (g.current_user.isAdmin or g.current_user.username == username or g.current_user.isCeltsStudentStaff):
return abort(403)

sustainedEngagementByTerm = getCommunityEngagementByTerm(username)

activeTab = request.args.get("tab", "sustainedCommunityEngagements")
Expand Down
35 changes: 29 additions & 6 deletions app/logic/celtsLabor.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,37 @@ def refreshCeltsLaborRecords(laborDict):
def getCeltsLaborHistory(volunteer):

laborHistoryList = list(CeltsLabor.select(CeltsLabor.positionTitle,
CeltsLabor.id,
Term.description,
Term.academicYear,
Term.isSummer)
.join(Term, on=(CeltsLabor.term == Term.id))
.where(CeltsLabor.user == volunteer))

.where(CeltsLabor.user == volunteer)
.order_by(Term.termOrder.asc()))
termsByAcademicYear = {}
for position in laborHistoryList:
if position.term.isSummer:
continue
academicYear = position.term.academicYear
description = position.term.description
if academicYear not in termsByAcademicYear:
termsByAcademicYear[academicYear] = {"Fall": False,"Spring": False}
if "Fall" in description:
termsByAcademicYear[academicYear]["Fall"] = True
elif "Spring" in description:
termsByAcademicYear[academicYear]["Spring"] = True
laborHistoryDict= {}
for position in laborHistoryList:
laborHistoryDict[position.positionTitle] = position.term.description if position.term.isSummer else position.term.academicYear

return laborHistoryDict
for position in laborHistoryList:
description = position.term.description
academicYear = position.term.academicYear
if position.term.isSummer:
positionTerm = description
else:
hasFall = termsByAcademicYear[academicYear]["Fall"]
hasSpring = termsByAcademicYear[academicYear]["Spring"]
if hasFall and hasSpring:
positionTerm = description
else:
positionTerm = f"AY {academicYear}"
laborHistoryDict[position.id] = (position.positionTitle,positionTerm)
return laborHistoryDict
39 changes: 32 additions & 7 deletions app/logic/searchUsers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from peewee import fn
from playhouse.shortcuts import model_to_dict
from app.models.user import User
def searchUsers(query, category=None):
Expand All @@ -8,14 +9,29 @@ def searchUsers(query, category=None):
'''
# add wildcards to each piece of the query
splitSearch = query.strip().split()
firstName = splitSearch[0] + "%"
lastName = " ".join(splitSearch[1:]) +"%"
if not splitSearch:
return User.select().where(False)
fullSearch = " ".join(splitSearch) + "%"
searchWhere = (User.firstName ** fullSearch | User.lastName ** fullSearch | User.username ** fullSearch)
for splitIndex in range(1, len(splitSearch)):
firstName = " ".join(splitSearch[:splitIndex]) + "%"
lastName = " ".join(splitSearch[splitIndex:]) + "%"

if len(splitSearch) == 1: # search for query in first OR last name
searchWhere = (User.firstName ** firstName | User.lastName ** firstName | User.username ** splitSearch)
else: # search for first AND last name
searchWhere = (User.firstName ** firstName & User.lastName ** lastName)
searchWhere |= (
(User.firstName ** firstName) &
(User.lastName ** lastName)
)

# Also allow individual pieces of the name to match
for namePart in splitSearch:
nameSearch = namePart + "%"

searchWhere |= (
(User.firstName ** nameSearch) |
(User.lastName ** nameSearch) |
(User.username ** nameSearch)
)

if category == "instructor":
userWhere = (User.isFaculty | User.isStaff)
elif category == "admin":
Expand All @@ -31,7 +47,16 @@ def searchUsers(query, category=None):
else:
userWhere = (User.isStudent)

fullSearchText = " ".join(splitSearch)
# Combine into query
searchResults = User.select().where(searchWhere, userWhere)
searchResults = User.select().where(searchWhere, userWhere).order_by(
fn.CONCAT(User.firstName, " ", User.lastName)
.contains(fullSearchText)
.desc(),
User.firstName.startswith(fullSearchText).desc(),
User.lastName.startswith(fullSearchText).desc(),
User.lastName,
User.firstName
)

return { user.username : model_to_dict(user) for user in searchResults }
2 changes: 1 addition & 1 deletion app/logic/volunteerSpreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def makeDataXls(sheetName, sheetData, workbook, sheetDesc=None):
if type(dataRows) == list:
for row, rowData in enumerate(dataRows):
col_idx = 0
for column, value in rowData.items():
for value in rowData:
# dates and times should use their text representation
if isinstance(value, (datetime, date, time)):
value = str(value)
Expand Down
2 changes: 1 addition & 1 deletion app/static/js/searchStudent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import searchUser from './searchUser.js'

function callback(selected) {
$("#searchStudentsInput").submit();
$("#searchStudentsInput").closest("form").submit();
}

$(document).ready(function() {
Expand Down
4 changes: 2 additions & 2 deletions app/templates/main/userProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ <h3 class="accordion-header" id="headingFour">
{% if participatedInLabor %}
<div class="col-md-6">
<h5>CELTS Labor History:</h5>
{% for program, term in participatedInLabor.items() %}
<p>{{term}}: {{program}}</p>
{% for positionTitle, term in participatedInLabor.values() %}
<p>{{term}}: {{positionTitle}}</p>
{% endfor %}
</div>
{% endif %}
Expand Down
4 changes: 3 additions & 1 deletion app/templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ <h6>Current User: {{g.current_user.username}}</h6>
<select name="newuser" class="form-select" style="margin-bottom: 10px" onchange="this.form.submit()">>
<option {{"selected" if g.current_user.username == config.default_user }} value="{{config.default_user}}">Default User: {{config.default_user}}</option>
<option {{"selected" if g.current_user.username == "ramsayb2"}} value="ramsayb2">Admin: ramsayb2</option>
<option {{"selected" if g.current_user.username == "neillz"}} value="neillz">Student Staff: neillz</option>
<option {{"selected" if g.current_user.username == "neillz"}} value="neillz">Program Manager: neillz</option>
<!--Scott Heggen as a placeholder for Operations Team until we have proper operations team member and their consent-->
<option {{"selected" if g.current_user.username == "heggens"}} value="heggens">Operations Team: heggens</option>
<option {{"selected" if g.current_user.username == "ayisie"}} value="ayisie">Student: ayisie</option>
<option {{"selected" if g.current_user.username == "heggens"}} value="heggens">Faculty: heggens</option>
</select>
Expand Down
19 changes: 15 additions & 4 deletions tests/code/test_celtsLabor.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,24 @@ def test_getCeltsLaborHistory():
isAcademicYear = True)


testDataAyisieHistory = {"Bonner Manager": "Summer 2021"}
testDataAyisieHistory = [('Bonner Manager', 'Summer 2021')]
getAyisieHistory = getCeltsLaborHistory(ayisie)

testDataMupotsalHistory = {"Habitat For Humanity Cord.": "2020-2021"}
testDataMupotsalHistory = [('Habitat For Humanity Cord.', 'AY 2020-2021')]
getMupotsalHistory = getCeltsLaborHistory(mupotsal)

assert getAyisieHistory == testDataAyisieHistory
assert getMupotsalHistory == testDataMupotsalHistory
assert list(getAyisieHistory.values()) == testDataAyisieHistory
assert list(getMupotsalHistory.values()) == testDataMupotsalHistory

CeltsLabor.create(user = mupotsal,
positionTitle = "Bonner Manager",
term = Term.get_by_id(1),
isAcademicYear = True)

#this is to test if there are two different celts labor in a academic year it no longers show AY 2020-2021 instead shows Fall and Spring in ascending order
testDataMupotsalHistoryFallSpring = [('Bonner Manager', 'Fall 2020'), ('Habitat For Humanity Cord.', 'Spring 2021')]
getMupotsalHistory = getCeltsLaborHistory(mupotsal)

assert list(getMupotsalHistory.values()) == testDataMupotsalHistoryFallSpring

transaction.rollback()
10 changes: 10 additions & 0 deletions tests/code/test_spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,11 @@ def test_getUniqueVolunteers(fixture_info):

@pytest.mark.integration
def test_laborAttendanceByTerm(fixture_info):
for event in (fixture_info['event1'], fixture_info['event2'], fixture_info['event3']):
event.isService = False
event.isLaborOnly = True
event.save()

columns, results = laborAttendanceByTerm(fixture_info['term1'])
results = list(results)

Expand Down Expand Up @@ -740,6 +745,11 @@ def test_laborAttendanceByTerm(fixture_info):

EventParticipant.create(event=fixture_info['event3'], user=fixture_info['user1'], hoursEarned=2)

for event in (fixture_info['event1'], fixture_info['event2'], fixture_info['event3']):
event.isService = True
event.isLaborOnly = False
event.save()

@pytest.mark.integration
def test_graduatingSeniorsVolunteerHours(fixture_info):
columns, rows = graduatingSeniorsVolunteerHours("2024-2025-test")
Expand Down
Loading