Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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: 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: "USE local-override.yml"

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
20 changes: 11 additions & 9 deletions app/logic/celtsLabor.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ def refreshCeltsLaborRecords(laborDict):
for positionTitle, termNames in value.items():
for term in termNames:
termTableMatch = Term.select()
if term[0].isalpha():
isAcademicYear = False

if term[0].isalpha(): # Fall, Spring, Summer
termTableMatch = termTableMatch.where(Term.description == term)
else:
else: # e.g., 2025-2026
termTableMatch = termTableMatch.where(Term.academicYear == term, Term.description % "Fall%")
isAcademicYear = True

try:
laborTerm = termTableMatch.get()
isAcademicYear = not laborTerm.isSummer
celtsLabor.append({"user": key,
"positionTitle": positionTitle,
"term": laborTerm,
Expand All @@ -117,14 +120,13 @@ def refreshCeltsLaborRecords(laborDict):
def getCeltsLaborHistory(volunteer):

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

laborHistoryDict= {}
for position in laborHistoryList:
laborHistoryDict[position.positionTitle] = position.term.description if position.term.isSummer else position.term.academicYear
.where(CeltsLabor.user == volunteer)
.order_by(Term.termOrder.asc()))

return laborHistoryDict
return [(p.positionTitle, f"AY {p.term.academicYear}" if p.isAcademicYear else p.term.description) for p in laborHistoryList]
30 changes: 21 additions & 9 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 @@ -6,15 +7,19 @@ def searchUsers(query, category=None):

MySQL LIKE is case insensitive
'''
# add wildcards to each piece of the query
splitSearch = query.strip().split()
firstName = splitSearch[0] + "%"
lastName = " ".join(splitSearch[1:]) +"%"

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)
if not splitSearch:
return User.select().where(False)
searchWhere = None
for namePart in splitSearch:
nameSearch = namePart + "%"
# This individual search term can match the user's first name, last name, or username.
namePartWhere = (User.firstName.contains(namePart) | User.lastName.contains(namePart) | User.username.contains(namePart))
# For the first search term, initialize the WHERE condition.
if searchWhere is None:
searchWhere = namePartWhere
else:
searchWhere &= namePartWhere # Require every search term to match at least one of the first name, last name, or username fields.

if category == "instructor":
userWhere = (User.isFaculty | User.isStaff)
Expand All @@ -33,7 +38,14 @@ 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/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 @@ -294,8 +294,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 %}
<p>{{term}}: {{positionTitle}}</p>
{% endfor %}
</div>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion app/templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ <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>
<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
24 changes: 16 additions & 8 deletions tests/code/test_celtsLabor.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,24 @@ def test_getCeltsLaborHistory():
CeltsLabor.create(user = mupotsal,
positionTitle = "Habitat For Humanity Cord.",
term = Term.get_by_id(2),
isAcademicYear = True)
isAcademicYear = False)


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

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

assert getAyisieHistory == testDataAyisieHistory
assert getMupotsalHistory == testDataMupotsalHistory
assert testDataAyisieHistory == getCeltsLaborHistory(ayisie)
assert testDataMupotsalHistory == getCeltsLaborHistory(mupotsal)

transaction.rollback()
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', 'AY 2020-2021'), ('Habitat For Humanity Cord.', 'Spring 2021')]

assert testDataMupotsalHistoryFallSpring == getCeltsLaborHistory(mupotsal)

transaction.rollback()
2 changes: 1 addition & 1 deletion tests/code/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_searchUsers():
secondUser = User.create(username = 'sawconc', firstName = 'Candace', lastName = 'Sawcon', bnumber = '021556782', email = 'test@berea.edu', isStudent = True, cpoNumber = '1400')

searchResults = searchUsers('sa')
assert len(searchResults) == 2
assert len(searchResults) == 3
assert searchResults['lamichhanes2'] == model_to_dict(User.get_by_id('lamichhanes2'))
assert searchResults["sawconc"] == model_to_dict (User.get_by_id('sawconc'))
assert '(555)555-5555' in searchResults["lamichhanes2"].values()
Expand Down
Loading