Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to the invite cohort #1297

Open
wants to merge 34 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
85aaf3c
Changes to the invite cohort
Mbeweg Jul 25, 2024
9914f5e
Merge branch 'development' into BCI1
bledsoef Sep 6, 2024
d3dcc50
bonner cohort remain checked
doucoureb Sep 17, 2024
08aab57
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
doucoureb Sep 17, 2024
100f0cc
improved code
doucoureb Sep 20, 2024
5e10bdd
Merge branch 'development' into BCI1
doucoureb Oct 2, 2024
651a9c5
Merge branch 'development' of github.com:BCStudentSoftwareDevTeam/cel…
bledsoef Oct 3, 2024
3b62689
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
bledsoef Oct 3, 2024
616aa8c
Bonner Cohort checkbox fixed + merge conflict
doucoureb Oct 4, 2024
0842823
pr modifications
doucoureb Oct 9, 2024
d4078be
Ready for PR
Oct 18, 2024
d0a825b
invitation cohort attempt
doucoureb Oct 29, 2024
6ef35d2
pr test
doucoureb Oct 31, 2024
06c6d26
Merge branch 'development' of github.com:BCStudentSoftwareDevTeam/cel…
bledsoef Oct 31, 2024
f42411e
pr test
doucoureb Nov 4, 2024
1cd75cd
pr test 1
doucoureb Nov 8, 2024
231a773
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
bledsoef Nov 8, 2024
8c6e1d1
Merge branch 'development' into BCI1
bledsoef Nov 11, 2024
b42ce9a
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
bledsoef Nov 12, 2024
2646217
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
bledsoef Nov 12, 2024
a88b114
test pr 2
doucoureb Nov 12, 2024
d64297f
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
doucoureb Nov 12, 2024
cc12edb
PR test 3: I haven't moved the function inviteCohortsToEvent to the e…
doucoureb Nov 22, 2024
350f1aa
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
bledsoef Dec 3, 2024
401682c
Merge branch 'development' of github.com:BCStudentSoftwareDevTeam/cel…
bledsoef Dec 3, 2024
e179c8f
Change variables from snake_case to camelCasee
stevensonmichel Dec 26, 2024
a6a4f7d
Fixed checkbox for event cohort
stevensonmichel Dec 26, 2024
c022d6a
Merge branch 'development' into BCI1
stevensonmichel Dec 26, 2024
c28fd89
removed unnecessary codes and moved functions to logic
stevensonmichel Dec 27, 2024
a6e42dc
Finished test for inviteCohorts and updateCohorts to events functions
stevensonmichel Dec 30, 2024
0f55362
resolved many of the comments from print statements and removing cohorts
WackyWeaver Jan 14, 2025
6c3312a
Wrote tests for addBonnerCohortToRsvpLog logic
stevensonmichel Jan 20, 2025
ff1446e
Fixed duplicate rsvp logs when adding cohort in bonner scholar event
stevensonmichel Jan 24, 2025
20fefad
Merge branch 'development' into BCI1
stevensonmichel Jan 24, 2025
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
54 changes: 43 additions & 11 deletions app/controllers/admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from app.models.eventRsvpLog import EventRsvpLog
from app.models.attachmentUpload import AttachmentUpload
from app.models.bonnerCohort import BonnerCohort
from app.models.eventCohort import EventCohort
from app.models.certification import Certification
from app.models.user import User
from app.models.term import Term
Expand All @@ -30,7 +31,7 @@
from app.logic.createLogs import createActivityLog
from app.logic.certification import getCertRequirements, updateCertRequirements
from app.logic.utils import selectSurroundingTerms, getFilesFromRequest, getRedirectTarget, setRedirectTarget
from app.logic.events import attemptSaveMultipleOfferings, cancelEvent, deleteEvent, attemptSaveEvent, preprocessEventData, getRecurringEventsData, deleteEventAndAllFollowing, deleteAllRecurringEvents, getBonnerEvents,addEventView, getEventRsvpCount, copyRsvpToNewEvent, getCountdownToEvent, calculateNewMultipleOfferingId
from app.logic.events import attemptSaveMultipleOfferings, cancelEvent, deleteEvent, attemptSaveEvent, preprocessEventData, getRecurringEventsData, deleteEventAndAllFollowing, deleteAllRecurringEvents, getBonnerEvents,addEventView, getEventRsvpCount, copyRsvpToNewEvent, getCountdownToEvent, calculateNewMultipleOfferingId, inviteCohortsToEvent, updateEventCohorts
from app.logic.participants import getParticipationStatusForTrainings, checkUserRsvp
from app.logic.minor import getMinorInterest
from app.logic.fileHandler import FileHandler
Expand Down Expand Up @@ -131,11 +132,11 @@ def createEvent(templateid, programid):
validationErrorMessage = "Failed to save event."

if savedEvents:
rsvpcohorts = request.form.getlist("cohorts[]")
for year in rsvpcohorts:
rsvpForBonnerCohort(int(year), savedEvents[0].id)
addBonnerCohortToRsvpLog(int(year), savedEvents[0].id)

rsvpCohorts = request.form.getlist("cohorts[]")
if rsvpCohorts:
success, message, invitedCohorts = inviteCohortsToEvent(savedEvents[0], rsvpCohorts)
if not success:
flash(message, 'warning')

noun = ((eventData.get('isRecurring') or eventData.get('isMultipleOffering')) and "Events" or "Event") # pluralize
flash(f"{noun} successfully created!", 'success')
Expand Down Expand Up @@ -177,7 +178,14 @@ def createEvent(templateid, programid):
requirements, bonnerCohorts = [], []
if eventData['program'] is not None and eventData['program'].isBonnerScholars:
requirements = getCertRequirements(Certification.BONNER)
bonnerCohorts = getBonnerCohorts(limit=5)
rawBonnerCohorts = getBonnerCohorts(limit=5)
bonnerCohorts = {}

for year, cohort in rawBonnerCohorts.items():
if cohort:
bonnerCohorts[year] = cohort


return render_template(f"/events/{template.templateFile}",
template = template,
eventData = eventData,
Expand Down Expand Up @@ -259,6 +267,10 @@ def eventDisplay(eventId):
# Validate given URL
try:
event = Event.get_by_id(eventId)
invitedCohorts = list(EventCohort.select().where(
EventCohort.event == event
))
invitedYears = [str(cohort.year) for cohort in invitedCohorts]
except DoesNotExist as e:
print(f"Unknown event: {eventId}")
abort(404)
Expand Down Expand Up @@ -293,8 +305,9 @@ def eventDisplay(eventId):


if savedEvents:
rsvpcohorts = request.form.getlist("cohorts[]")
for year in rsvpcohorts:
rsvpCohorts = request.form.getlist("cohorts[]")
updateEventCohorts(savedEvents[0], rsvpCohorts)
for year in rsvpCohorts:
rsvpForBonnerCohort(int(year), event.id)
addBonnerCohortToRsvpLog(int(year), event.id)

Expand All @@ -314,18 +327,34 @@ def eventDisplay(eventId):

if eventData['program'] and eventData['program'].isBonnerScholars:
requirements = getCertRequirements(Certification.BONNER)
bonnerCohorts = getBonnerCohorts(limit=5)
rawBonnerCohorts = getBonnerCohorts(limit=5)
bonnerCohorts = {}

for year, cohort in rawBonnerCohorts.items():
if cohort:
bonnerCohorts[year] = cohort

print(1000*"*")
WackyWeaver marked this conversation as resolved.
Show resolved Hide resolved
print("The bonner cohorts are ", bonnerCohorts)

invitedCohorts = list(EventCohort.select().where(
EventCohort.event_id == eventId,
))
invitedYears = [str(cohort.year) for cohort in invitedCohorts]
else:
requirements, bonnerCohorts, invitedYears = [], [], []

rule = request.url_rule

# Event Edit
if 'edit' in rule.rule:
return render_template("events/createEvent.html",
eventData = eventData,
futureTerms=futureTerms,
futureTerms = futureTerms,
event = event,
requirements = requirements,
bonnerCohorts = bonnerCohorts,
invitedYears = invitedYears,
userHasRSVPed = userHasRSVPed,
isProgramManager = isProgramManager,
filepaths = filepaths)
Expand All @@ -350,6 +379,8 @@ def eventDisplay(eventId):
currentEventRsvpAmount = getEventRsvpCount(event.id)

userParticipatedTrainingEvents = getParticipationStatusForTrainings(eventData['program'], [g.current_user], g.current_term)



return render_template("events/eventView.html",
eventData=eventData,
Expand All @@ -361,6 +392,7 @@ def eventDisplay(eventId):
filepaths=filepaths,
image=image,
pageViewsCount=pageViewsCount,
invitedYears=invitedYears,
eventCountdown=eventCountdown
)

Expand Down
19 changes: 18 additions & 1 deletion app/logic/bonner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from app.models.bonnerCohort import BonnerCohort
from app.models.eventRsvp import EventRsvp
from app.models.user import User
from app.models.eventCohort import EventCohort
from app.logic.createLogs import createRsvpLog

def makeBonnerXls():
Expand Down Expand Up @@ -83,11 +84,27 @@ def rsvpForBonnerCohort(year, event):
.where(BonnerCohort.year == year),
[EventRsvp.user, EventRsvp.event, EventRsvp.rsvpTime]).on_conflict(action='IGNORE').execute()

# def updateEventBonnerCohort(year, event):
WackyWeaver marked this conversation as resolved.
Show resolved Hide resolved
# """
# Updates the Bonner Cohorts for a given event
# """
# eventCohort = EventCohort.select(EventCohort.where(event == event))
# EventCohort.update()


# def AddEventBonnerCohort(year, event):
# """
# Adds the Bonner Cohorts for a given event
# """
# eventCohort = EventCohort.create(event == event, year == year, invited_at =)
# EventCohort.update()


def addBonnerCohortToRsvpLog(year, event):
""" This method adds the table information in the RSVP Log page"""
bonnerCohort = list(BonnerCohort.select(fn.CONCAT(User.firstName, ' ', User.lastName).alias("fullName"))
.join(User, on=(User.username == BonnerCohort.user))
.where(BonnerCohort.year == year))
for bonner in bonnerCohort:
fullName = bonner.fullName
createRsvpLog(eventId=event, content=f"Added {fullName} to RSVP list.")
createRsvpLog(eventId=event, content=f"Added {fullName} to RSVP list.")
76 changes: 76 additions & 0 deletions app/logic/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
from app.models.requirementMatch import RequirementMatch
from app.models.certificationRequirement import CertificationRequirement
from app.models.eventViews import EventView
from app.models.eventCohort import EventCohort

from app.logic.bonner import rsvpForBonnerCohort, addBonnerCohortToRsvpLog
from app.logic.createLogs import createActivityLog, createRsvpLog
from app.logic.utils import format24HourTime
from app.logic.fileHandler import FileHandler
Expand Down Expand Up @@ -706,3 +708,77 @@ def copyRsvpToNewEvent(priorEvent, newEvent):
numRsvps = len(rsvpInfo)
if numRsvps:
createRsvpLog(newEvent, f"Copied {numRsvps} Rsvps from {priorEvent['name']} to {newEvent.name}")


def inviteCohortsToEvent(event, cohortYears):
"""
Invites cohorts to a newly created event by associating the cohorts directly.
"""
invitedCohorts = []
try:
for year in cohortYears:
year = int(year)
EventCohort.get_or_create(
event=event,
year=year,
defaults={'invited_at': datetime.now()}
)

addBonnerCohortToRsvpLog(year, event.id)
rsvpForBonnerCohort(year, event.id)
invitedCohorts.append(year)

if invitedCohorts:
cohortList = ', '.join(map(str, invitedCohorts))
createActivityLog(f"Added Bonner cohorts {cohortList} for newly created event {event.name}")

return True, "Cohorts successfully added to new event", invitedCohorts

except Exception as e:
print(f"Error inviting cohorts to new event: {e}")
return False, f"Error adding cohorts to new event: {e}", []


def updateEventCohorts(event, cohortYears):
stevensonmichel marked this conversation as resolved.
Show resolved Hide resolved
"""
Updates the cohorts for an existing event by adding new ones and removing outdated ones.
"""
invitedCohorts = []
try:
precedentInvitedCohorts = list(EventCohort.select().where(EventCohort.event == event))
precedentInvitedYears = [str(precedentCohort.year) for precedentCohort in precedentInvitedCohorts]

yearsToAdd = [int(year) for year in cohortYears if year not in precedentInvitedYears]

if not cohortYears:
yearsToRemove = [int(year) for year in precedentInvitedYears]
else:
yearsToRemove = [int(year) for year in precedentInvitedYears if year not in cohortYears]

if yearsToRemove:
EventCohort.delete().where(
(EventCohort.event == event) & (EventCohort.year.in_(yearsToRemove))
).execute()

for year in yearsToAdd:
EventCohort.get_or_create(
event=event,
year=year,
defaults={'invited_at': datetime.now()}
)

addBonnerCohortToRsvpLog(year, event.id)
rsvpForBonnerCohort(year, event.id)
invitedCohorts.append(year)

if yearsToAdd or yearsToRemove:
cohortList = ', '.join(map(str, invitedCohorts))
createActivityLog(f"Updated Bonner cohorts for event {event.name}. Added: {yearsToAdd}, Removed: {yearsToRemove}")

return True, "Cohorts successfully updated for event", invitedCohorts

except Exception as e:
print(f"Error updating cohorts for event: {e}")
return False, f"Error updating cohorts for event: {e}", []


13 changes: 13 additions & 0 deletions app/models/eventCohort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from datetime import datetime
from app.models import*
from app.models.event import Event
from app.models.bonnerCohort import BonnerCohort

class EventCohort(baseModel):
event = ForeignKeyField(Event)
year = IntegerField()
invited_at = DateTimeField(default=datetime.now)

class Meta:
indexes = ( (('event', 'year'), True), )

9 changes: 5 additions & 4 deletions app/static/js/createEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,12 @@ function formatDate(originalDate) {
*/
$(document).ready(function() {
//makes sure bonners toggle will stay on between event pages
if (window.location.pathname == '/event/' + $('#newEventID').val() + '/edit') {
if ($("#checkBonners")) {
$("#checkBonners").prop('checked', true);
if (window.location.pathname == '/event/' + $('#newEventID').val() + '/edit') {
if ($("#checkBonners")) {
$("#checkBonners").prop('checked', true);
}
}
}

// Initialize datepicker with proper options
$.datepicker.setDefaults({
dateFormat: 'yy/mm/dd', // Ensures compatibility across browsers
Expand Down
14 changes: 10 additions & 4 deletions app/templates/events/createEvent.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,17 @@ <h1 id="pageTitle">{{page_title}}</h1>
<div class="row col-md-12 mb-4">
<div class="form-group">
<label class="form-label fw-bold">Invite Cohort(s)</label>
{% for year,students in bonnerCohorts.items()|reverse %}
{% for year, students in bonnerCohorts.items() | reverse %}
<div class="form-check">
<input class="form-check-input" type="checkbox" value="{{year}}" name="cohorts[]" id="cohort-{{year}}">
<label class="form-check-label text-truncate w-100" for="cohort-{{year}}">{{year}}-{{year+1}}
<span class="text-muted">({{students|map(attribute='fullName')|join(", ")}})</span>
<input class="form-check-input" type="checkbox" value="{{year}}" name="cohorts[]" id="cohort-{{year}}"
{% if invitedYears and year|string in invitedYears %}
stevensonmichel marked this conversation as resolved.
Show resolved Hide resolved
checked
{% endif %}>
<label class="form-check-label text-truncate w-100" for="cohort-{{year}}">
{{year}}-{{year+1}}
<span class="text-muted">
({{students | map(attribute='fullName') | join(", ")}})
</span>
</label>
</div>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion app/templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{% if g.current_user.isAdmin %}
<li>
<a href="/eventTemplates" class="nav-link text-white {{'active' if 'eventTemplates' in request.path}}" {{"aria-current='page'" if 'eventTemplates' in request.path}}>
Create Event
Create Event
</a>
</li>
<li>
Expand Down
1 change: 1 addition & 0 deletions database/migrate_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pem add app.models.eventRsvpLog.EventRsvpLog
pem add app.models.celtsLabor.CeltsLabor
pem add app.models.communityEngagementRequest.CommunityEngagementRequest
pem add app.models.individualRequirement.IndividualRequirement
pem add app.models.eventCohort.EventCohort


pem watch
Expand Down
Loading
Loading