Skip to content
Merged
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
14 changes: 7 additions & 7 deletions app/logic/events.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions app/templates/main/userProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ <h3 class="accordion-header" id="headingTwo">
<thead>
<th scope="col">Program</th>
<th scope="col">Event Name</th>
<th scope="col">Participation Type</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>
<td nowrap>{{event.startDate.strftime('%m/%d/%Y')}}</td>
</tr>
{% endfor %}
Expand Down
95 changes: 95 additions & 0 deletions tests/code/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading