Skip to content
Open
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
34 changes: 17 additions & 17 deletions app/controllers/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from app.models.courseInstructor import CourseInstructor
from app.models.backgroundCheckType import BackgroundCheckType

from app.logic.events import getUpcomingEventsForUser, getParticipatedEventsForUser, getTrainingEvents, getEventRsvpCountsForTerm, getUpcomingStudentLedCount, getStudentLedEvents, getBonnerEvents, getOtherEvents, getEngagementEvents
from app.logic.events import getUpcomingEventsForUser, getParticipatedEventsForUser, getTrainingEvents, getEventRsvpCountsForTerm, getUpcomingVolunteerOpportunitiesCount, getVolunteerOpportunities, getBonnerEvents, getCeltsLabor, getEngagementEvents
from app.logic.transcript import *
from app.logic.loginManager import logout
from app.logic.searchUsers import searchUsers
Expand Down Expand Up @@ -69,7 +69,7 @@ def landingPage():
def goToEventsList(programID):
return {"activeTab": getActiveEventTab(programID)}

@main_bp.route('/eventsList/<selectedTerm>', methods=['GET'], defaults={'activeTab': "studentLedEvents", 'programID': 0})
@main_bp.route('/eventsList/<selectedTerm>', methods=['GET'], defaults={'activeTab': "volunteerOpportunities", 'programID': 0})
@main_bp.route('/eventsList/<selectedTerm>/<activeTab>', methods=['GET'], defaults={'programID': 0})
@main_bp.route('/eventsList/<selectedTerm>/<activeTab>/<programID>', methods=['GET'])
def events(selectedTerm, activeTab, programID):
Expand All @@ -85,33 +85,33 @@ def events(selectedTerm, activeTab, programID):
term: Term = Term.get_by_id(currentTerm)

currentEventRsvpAmount = getEventRsvpCountsForTerm(term)
studentLedEvents = getStudentLedEvents(term)
countUpcomingStudentLedEvents = getUpcomingStudentLedCount(term, currentTime)
volunteerOpportunities = getVolunteerOpportunities(term)
countUpcomingVolunteerOpportunities = getUpcomingVolunteerOpportunitiesCount(term, currentTime)
trainingEvents = getTrainingEvents(term, g.current_user)
engagementEvents = getEngagementEvents(term)
bonnerEvents = getBonnerEvents(term)
otherEvents = getOtherEvents(term)
celtsLabor = getCeltsLabor(term)

managersProgramDict = getManagerProgramDict(g.current_user)

# Fetch toggle state from session
toggleState = request.args.get('toggleState', 'unchecked')

# compile all student led events into one list
# compile all volunteer opportunitiesevents into one list
studentEvents = []
for studentEvent in studentLedEvents.values():
for studentEvent in volunteerOpportunities.values():
studentEvents += studentEvent # add all contents of studentEvent to the studentEvents list

# Get the count of all term events for each category to display in the event list page.
studentLedEventsCount: int = len(studentEvents)
volunteerOpportunitiesCount: int = len(studentEvents)
trainingEventsCount: int = len(trainingEvents)
engagementEventsCount: int = len(engagementEvents)
bonnerEventsCount: int = len(bonnerEvents)
otherEventsCount: int = len(otherEvents)
celtsLaborCount: int = len(celtsLabor)

# gets only upcoming events to display in indicators
if (toggleState == 'unchecked'):
studentLedEventsCount: int = sum(list(countUpcomingStudentLedEvents.values()))
volunteerOpportunitiesCount: int = sum(list(countUpcomingVolunteerOpportunities.values()))
for event in trainingEvents:
if event.isPastEnd:
trainingEventsCount -= 1
Expand All @@ -121,28 +121,28 @@ def events(selectedTerm, activeTab, programID):
for event in bonnerEvents:
if event.isPastEnd:
bonnerEventsCount -= 1
for event in otherEvents:
for event in celtsLabor:
if event.isPastEnd:
otherEventsCount -= 1
celtsLaborCount -= 1

# Handle ajax request for Event category header number notifiers and toggle
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
return jsonify({
"studentLedEventsCount": studentLedEventsCount,
"volunteerOpportunitiesCount": volunteerOpportunitiesCount,
"trainingEventsCount": trainingEventsCount,
"engagementEventsCount": engagementEventsCount,
"bonnerEventsCount": bonnerEventsCount,
"otherEventsCount": otherEventsCount,
"celtsLaborCount": celtsLaborCount,
"toggleStatus": toggleState
})

return render_template("/events/eventList.html",
selectedTerm = term,
studentLedEvents = studentLedEvents,
volunteerOpportunities = volunteerOpportunities,
trainingEvents = trainingEvents,
engagementEvents = engagementEvents,
bonnerEvents = bonnerEvents,
otherEvents = otherEvents,
celtsLabor = celtsLabor,
listOfTerms = listOfTerms,
rsvpedEventsID = rsvpedEventsID,
currentEventRsvpAmount = currentEventRsvpAmount,
Expand All @@ -151,7 +151,7 @@ def events(selectedTerm, activeTab, programID):
activeTab = activeTab,
programID = int(programID),
managersProgramDict = managersProgramDict,
countUpcomingStudentLedEvents = countUpcomingStudentLedEvents,
countUpcomingVolunteerOpportunities = countUpcomingVolunteerOpportunities,
toggleState = toggleState,
)

Expand Down
61 changes: 30 additions & 31 deletions app/logic/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,17 @@ def saveEventToDb(newEventData, renewedEvent = False):
eventRecords.append(eventRecord)
return eventRecords

def getStudentLedEvents(term):
studentLedEvents = list(Event.select(Event, Program)
def getVolunteerOpportunities(term):
volunteerOpportunities = list(Event.select(Event, Program)
.join(Program)
.where(Program.isStudentLed,
Event.term == term, Event.deletionDate == None)
.where(Program.isVolunteerOpportunities,
Event.term == term, Event.isService == True, Event.deletionDate == None)
.order_by(Event.startDate, Event.timeStart)
.execute())

programs = {}

for event in studentLedEvents:
for event in volunteerOpportunities:
programs.setdefault(event.program, []).append(event)

return programs
Expand All @@ -248,15 +248,15 @@ def getEngagementEvents(term):
.execute())
return engagementEvents

def getUpcomingStudentLedCount(term, currentTime):
def getUpcomingVolunteerOpportunitiesCount(term, currentTime):
"""
Return a count of all upcoming events for each student led program.
Return a count of all upcoming events for each volunteer opportunitiesprogram.
"""

upcomingCount = (Program.select(Program.id, fn.COUNT(Event.id).alias("eventCount"))
.join(Event, on=(Program.id == Event.program_id))
.where(Program.isStudentLed,
Event.term == term, Event.deletionDate == None,
.where(Program.isVolunteerOpportunities,
Event.term == term, Event.isService == True, Event.deletionDate == None,
(Event.startDate > currentTime) | ((Event.startDate == currentTime) & (Event.timeEnd >= currentTime)),
Event.isCanceled == False)
.group_by(Program.id))
Expand Down Expand Up @@ -290,36 +290,35 @@ def getTrainingEvents(term, user):
return list(trainingQuery.execute())

def getBonnerEvents(term):
bonnerScholarsEvents = list(Event.select(Event, Program.id.alias("program_id"))
.join(Program)
.where(Program.isBonnerScholars,
Event.term == term, Event.deletionDate == None)
.order_by(Event.startDate, Event.timeStart)
.execute())
bonnerScholarsEvents = list(
Event.select(Event, Program.id.alias("program_id"))
.join(Program)
.where(
Program.isBonnerScholars,
Event.term == term,
Event.deletionDate == None
)
.order_by(Event.startDate, Event.timeStart)
.execute()
)
return bonnerScholarsEvents

def getOtherEvents(term):
def getCeltsLabor(term):
"""
Get the list of the events not caught by other functions to be displayed in
the Other Events section of the Events List page.
:return: A list of Other Event objects

Get the list of the labor only events to be displayed in
the Celts Labor section of the Events List page.
:return: A list of labor only Event objects
"""
# Gets all events that are not associated with a program and are not trainings
# Gets all events that have a program but don't fit anywhere
# Gets all events that are labor only

otherEvents = list(Event.select(Event, Program)
.join(Program, JOIN.LEFT_OUTER)
.where(Event.term == term, Event.deletionDate == None,
Event.isTraining == False,
Event.isAllVolunteerTraining == False,
((Program.isOtherCeltsSponsored) |
((Program.isStudentLed == False) &
(Program.isBonnerScholars == False))))
celtsLabor = list(Event.select()
.join(Program, JOIN.LEFT_OUTER, on=(Event.program == Program.id))
.where(Program.isCeltsLabor, Event.term == term, Event.deletionDate == None, Event.isLaborOnly == True)
.order_by(Event.startDate, Event.timeStart, Event.id)
.execute())

return otherEvents
return celtsLabor

def getUpcomingEventsForUser(user, asOf=datetime.now(), program=None):
"""
Expand Down
6 changes: 3 additions & 3 deletions app/logic/landingPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def getActiveEventTab(programID):
program = Program.get_by_id(programID)
if program.isBonnerScholars:
return "bonnerScholarsEvents"
elif program.isStudentLed:
return "studentLedEvents"
elif program.isVolunteerOpportunities:
return "volunteerOpportunities"
else:
return "otherEvents"
return "celtsLabor"
2 changes: 1 addition & 1 deletion app/models/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Program(baseModel):
bereaUrl = TextField(null=True)
programDescription = TextField()
partner = CharField(null=True)
isStudentLed = BooleanField(default=False)
isVolunteerOpportunities = BooleanField(default=False)
isBonnerScholars = BooleanField(default=False)
isOtherCeltsSponsored = BooleanField(default=False)
contactName = CharField(null=True,default='')
Expand Down
8 changes: 4 additions & 4 deletions app/static/js/eventList.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@ function updateIndicatorCounts(isChecked){
toggleState: isChecked ? "checked" : "unchecked",
},
success: function(eventsCount) {
const studentLedEventsCount = Number(eventsCount.studentLedEventsCount);
const volunteerOpportunitiesCount = Number(eventsCount.volunteerOpportunitiesCount);
const trainingEventsCount = Number(eventsCount.trainingEventsCount);
const engagementEventsCount = Number(eventsCount.engagementEventsCount);
const bonnerEventsCount = Number(eventsCount.bonnerEventsCount);
const otherEventsCount = Number(eventsCount.otherEventsCount);
const celtsLaborCount = Number(eventsCount.celtsLaborCount);
const toggleStatus = eventsCount.toggleStatus;

$("#viewPastEventsToggle").prop(toggleStatus, true);

// use ternary operators to populate the tab with a number if there are events, and clear the count if there are none
studentLedEventsCount > 0 ? $("#studentLedEvents").html(`Student-Led Services (${studentLedEventsCount})`) : $("#studentLedEvents").html(`Student-Led Services`)
volunteerOpportunitiesCount > 0 ? $("#volunteerOpportunities").html(`Volunteer Opportunities (${volunteerOpportunitiesCount})`) : $("#volunteerOpportunities").html(`Volunteer Opportunities`)
trainingEventsCount > 0 ? $("#trainingEvents").html(`Trainings (${trainingEventsCount})`) : $("#trainingEvents").html(`Trainings`)
engagementEventsCount > 0 ? $("#engagementEvents").html(`Education and Engagement (${engagementEventsCount})`) : $("#engagementEvents").html('Education and Engagement')
bonnerEventsCount > 0 ? $("#bonnerScholarsEvents").html(`Bonner Scholars (${bonnerEventsCount})`) : $("#bonnerScholarsEvents").html(`Bonner Scholars`)
otherEventsCount > 0 ? $("#otherEvents").html(`Other Events (${otherEventsCount})`) : $("#otherEvents").html(`Other Events`)
celtsLaborCount > 0 ? $("#celtsLabor").html(`Celts Labor (${celtsLaborCount})`) : $("#celtsLabor").html(`Celts Labor`)
},
error: function(request, status, error) {
console.log(status,error);
Expand Down
2 changes: 1 addition & 1 deletion app/static/js/landingPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $(document).ready(function(){
url: "/goToEventsList/"+programID,
type: "GET",
success: function(response) {
if (response.activeTab === "studentLedEvents"){
if (response.activeTab === "volunteerOpportunities"){
window.location.href += "eventsList/"+term+"/"+response.activeTab+"/"+programID
} else {
window.location.href += "eventsList/"+term+"/"+response.activeTab
Expand Down
Loading
Loading