Skip to content
Merged
3 changes: 1 addition & 2 deletions app/controllers/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from app.models.programManager import ProgramManager
from app.models.backgroundCheck import BackgroundCheck
from app.models.emergencyContact import EmergencyContact
from app.models.eventParticipant import EventParticipant
from app.models.courseInstructor import CourseInstructor
from app.models.backgroundCheckType import BackgroundCheckType

Expand Down Expand Up @@ -234,8 +233,8 @@ def viewUsersProfile(username):
managersProgramDict = getManagerProgramDict(g.current_user)
managersList = [id[1] for id in managersProgramDict.items()]
totalSustainedEngagements = getEngagementTotal(getCommunityEngagementByTerm(volunteer))
handbookOverdue = getHandbookStatus(volunteer)

handbookOverdue = getHandbookStatus(volunteer)
training = hasGoneToTraining(g.current_user, g.current_term)

return render_template ("/main/userProfile.html",
Expand Down
24 changes: 17 additions & 7 deletions app/logic/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,22 +411,32 @@ def getParticipatedEventsForUser(user):
:return: A list of Event objects
"""

# Does this handle labor only and/or includes labor events?
participatedEvents = (Event.select(Event, Program.programName, Case(None, (
((Event.allowsLabor | Event.name.contains("Labor")) & Event.isService, "Labor & Volunteer"),
((Event.allowsLabor | Event.isLaborOnly | Event.name.contains("Labor")), "Labor"),
(Event.isService, "Volunteer")), "Attendee").alias("participatedType"))
eventName = fn.LOWER(Event.name)
checkIfLaborMeeting = eventName.contains("labor meeting")

participatedEvents = (Event.select(Event,
Program.programName,
Case(None,
(
((Event.allowsLabor | Event.name.contains("Labor")) & Event.isService, "Labor & Volunteer"),
((Event.allowsLabor | Event.isLaborOnly | Event.name.contains("Labor")), "Labor"),
(Event.isService, "Volunteer")
),
"Attendee").alias("participatedType"),
EventParticipant.hoursEarned
)
.join(Program, JOIN.LEFT_OUTER).switch()
.join(EventParticipant)
.where(EventParticipant.user == user,
Event.isAllVolunteerTraining == False, Event.deletionDate == None, Event.isCeltsTraining == False)
.order_by(Event.startDate, Event.name))
allVolunteer = (Event.select(Event, "", Value("Volunteer").alias("participatedType"))

allVolunteer = (Event.select(Event, "", Value("Volunteer").alias("participatedType"), Value(0).alias("hoursEarned"))
.join(EventParticipant)
.where(Event.isAllVolunteerTraining == True,
EventParticipant.user == user))
union = participatedEvents.union_all(allVolunteer)
unionParticipationWithVolunteer = list(union.select_from(union.c.id, union.c.programName, union.c.startDate, union.c.name, union.c.participatedType).order_by(union.c.startDate, union.c.name).execute())
unionParticipationWithVolunteer = list(union.select_from(union.c.id, union.c.isService, union.c.programName, union.c.startDate, union.c.name, union.c.participatedType, union.c.hoursEarned).order_by(union.c.startDate, union.c.name).execute())
return unionParticipationWithVolunteer

def validateNewEventData(data):
Expand Down
6 changes: 6 additions & 0 deletions app/templates/main/userProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,19 @@ <h3 class="accordion-header" id="headingTwo">
<th scope="col">Program</th>
<th scope="col">Event Name</th>
<th scope="col">Participation Type</th>
<th scope="col">Service Hours</th>
<th scope="col">Event Date</th>
</thead>
{% for event in participatedEvents %}
<tr>
<td>{{event.programName}}</td>
<td><a href= '/event/{{event.id}}/view' class="link-primary">{{event.name}}</a></td>
<td>{{event.participatedType}}</td>
{% if event.isService %}
<td>{{event.hoursEarned}}</td>
{% else %}
<td>N/A</td>
{% endif %}
<td nowrap>{{event.startDate.strftime('%m/%d/%Y')}}</td>
</tr>
{% endfor %}
Expand Down
18 changes: 15 additions & 3 deletions tests/code/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ def test_volunteerHistory():
startDate = "2021-12-12",
isAllVolunteerTraining = False,
program = participatedProgram)

# Create a non-program event in the past that the test user will have
# participated in
participatedEvent = Event.create(name = "Attended event",
Expand Down Expand Up @@ -1024,7 +1025,7 @@ def test_calculateNewSeriesId():
assert calculateNewSeriesId() == maxSeriesId

@pytest.mark.integration
def test_getParticipatedEventsForUser_participatedTypes():
def test_getParticipatedEventsForUser_typesAndHours():
with mainDB.atomic() as transaction:
user = User.create(
username='usrtst2',
Expand Down Expand Up @@ -1105,19 +1106,30 @@ def test_getParticipatedEventsForUser_participatedTypes():

EventParticipant.create(user=user, event=allVolunteerTrainingEvent)
EventParticipant.create(user=user, event=laborEvent)
EventParticipant.create(user=user, event=volunteerEvent)
EventParticipant.create(user=user, event=laborVolunteerEvent)
EventParticipant.create(user=user, event=volunteerEvent, hoursEarned=5)
EventParticipant.create(user=user, event=laborVolunteerEvent, hoursEarned=3)

result = getParticipatedEventsForUser(user)

participatedTypes = {
event.name: event.participatedType for event in result
}

serviceHoursEarned = {
event.name: event.hoursEarned for event in result
}

assert participatedTypes["Labor shift"] == "Labor"
assert serviceHoursEarned["Labor shift"] == 0

assert participatedTypes["Volunteer event"] == "Volunteer"
assert serviceHoursEarned["Volunteer event"] == 5

assert participatedTypes["Labor volunteer event"] == "Labor & Volunteer"
assert serviceHoursEarned["Labor volunteer event"] == 3

assert participatedTypes["All Volunteer Training"] == "Volunteer"
assert serviceHoursEarned["All Volunteer Training"] == 0

transaction.rollback()

Expand Down
Loading