diff --git a/app/logic/events.py b/app/logic/events.py index 822d85632..09b3e286f 100644 --- a/app/logic/events.py +++ b/app/logic/events.py @@ -1,5 +1,5 @@ from flask import url_for, g, session -from peewee import DoesNotExist, fn, JOIN +from peewee import DoesNotExist, fn, JOIN, Case, Value from dateutil import parser from datetime import timedelta, date, datetime from dateutil.relativedelta import relativedelta @@ -398,21 +398,21 @@ def getParticipatedEventsForUser(user): Used in testing, defaults to the current timestamp. :return: A list of Event objects """ - - participatedEvents = (Event.select(Event, Program.programName) + participatedEvents = (Event.select(Event, Program.programName, Case(None, ( + ((Event.isLaborOnly | Event.name.contains("Labor")) & Event.isService, "Labor & Volunteer"), + ((Event.isLaborOnly | Event.name.contains("Labor")), "Labor"), + (Event.isService, "Volunteer")), "Attendee").alias("participatedType")) .join(Program, JOIN.LEFT_OUTER).switch() .join(EventParticipant) .where(EventParticipant.user == user, Event.isAllVolunteerTraining == False, Event.deletionDate == None) .order_by(Event.startDate, Event.name)) - - allVolunteer = (Event.select(Event, "") + allVolunteer = (Event.select(Event, "", Value("Volunteer").alias("participatedType")) .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).order_by(union.c.startDate, union.c.name).execute()) - + 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()) return unionParticipationWithVolunteer def validateNewEventData(data): diff --git a/app/templates/main/userProfile.html b/app/templates/main/userProfile.html index e29db4895..49fa59764 100644 --- a/app/templates/main/userProfile.html +++ b/app/templates/main/userProfile.html @@ -167,12 +167,14 @@

Program Event Name + Participation Type Event Date {% for event in participatedEvents %} {{event.programName}} {{event.name}} + {{event.participatedType}} {{event.startDate.strftime('%m/%d/%Y')}} {% endfor %} diff --git a/tests/code/test_events.py b/tests/code/test_events.py index 687fed4fe..7f24e1053 100644 --- a/tests/code/test_events.py +++ b/tests/code/test_events.py @@ -1023,6 +1023,101 @@ def test_calculateNewSeriesId(): maxSeriesId += 1 assert calculateNewSeriesId() == maxSeriesId +@pytest.mark.integration +def test_getParticipatedEventsForUser_participatedTypes(): + with mainDB.atomic() as transaction: + user = User.create( + username='usrtst2', + firstName='Test', + lastName='User', + bnumber='03522493', + email='user2@berea.edu', + isStudent=True + ) + + program = Program.create( + id=14, + programName="BOO", + isBonnerScholars=False, + contactEmail="test@email", + contactName="testName" + ) + + laborEvent = Event.create( + name="Labor shift", + term=2, + description="Labor event", + timeStart="18:00:00", + timeEnd="21:00:00", + location="The moon", + startDate="2021-12-12", + isAllVolunteerTraining=False, + isLaborOnly=True, + isService=False, + program=program + ) + + volunteerEvent = Event.create( + name="Volunteer event", + term=2, + description="Volunteer event", + timeStart="18:00:00", + timeEnd="21:00:00", + location="The moon", + startDate="2021-12-13", + isAllVolunteerTraining=False, + isLaborOnly=False, + isService=True, + program=program + ) + + laborVolunteerEvent = Event.create( + name="Labor volunteer event", + term=2, + description="Labor and volunteer event", + timeStart="18:00:00", + timeEnd="21:00:00", + location="The moon", + startDate="2021-12-14", + isAllVolunteerTraining=False, + isLaborOnly=True, + isService=True, + program=program + ) + + allVolunteerTrainingEvent = Event.create( + name="All Volunteer Training", + term=2, + description="All volunteer training event", + timeStart="18:00:00", + timeEnd="21:00:00", + location="The moon", + startDate="2021-12-15", + isAllVolunteerTraining=True, + isLaborOnly=False, + isService=False, + program=program + ) + + EventParticipant.create(user=user, event=allVolunteerTrainingEvent) + EventParticipant.create(user=user, event=laborEvent) + EventParticipant.create(user=user, event=volunteerEvent) + EventParticipant.create(user=user, event=laborVolunteerEvent) + + result = getParticipatedEventsForUser(user) + + participatedTypes = { + event.name: event.participatedType for event in result + } + + assert participatedTypes["Labor shift"] == "Labor" + assert participatedTypes["Volunteer event"] == "Volunteer" + assert participatedTypes["Labor volunteer event"] == "Labor & Volunteer" + assert participatedTypes["All Volunteer Training"] == "Volunteer" + + transaction.rollback() + + @pytest.mark.integration def test_getPreviousRecurringEventData(): with mainDB.atomic() as transaction: