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
5 changes: 5 additions & 0 deletions packet/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import click

from packet.mail import send_start_packet_mail
from packet.notifications import packet_starting_notification, packets_starting_notification
from . import app, db
from .models import Freshman, Packet, FreshSignature, UpperSignature, MiscSignature
from .ldap import ldap_get_eboard_role, ldap_get_active_rtps, ldap_get_3das, ldap_get_webmasters, \
Expand Down Expand Up @@ -125,13 +126,17 @@ def create_packets(freshmen_csv):
c_m = ldap_get_constitutional_maintainers()
drink = ldap_get_drink_admins()

# Packet starting notifications
packets_starting_notification(start)

# Create the new packets and the signatures for each freshman in the given CSV
freshmen_in_csv = parse_csv(freshmen_csv)
print("Creating DB entries and sending emails...")
for freshman in Freshman.query.filter(Freshman.rit_username.in_(freshmen_in_csv)).all():
packet = Packet(freshman=freshman, start=start, end=end)
db.session.add(packet)
send_start_packet_mail(packet)
packet_starting_notification(packet)

for member in all_upper:
sig = UpperSignature(packet=packet, member=member.uid)
Expand Down
24 changes: 23 additions & 1 deletion packet/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def packet_signed_notification(packet, signer):
def packet_100_percent_notification(packet):
member_subscriptions = NotificationSubscription.query.filter(NotificationSubscription.member.isnot(None))
intro_subscriptions = NotificationSubscription.query.filter(NotificationSubscription.freshman_username.isnot(None))

if member_subscriptions or intro_subscriptions:
notification_body = post_body
notification_body["contents"]["en"] = packet.freshman.name + ' got 💯 on packet!'
Expand All @@ -49,3 +48,26 @@ def packet_100_percent_notification(packet):

send_notification(notification_body, member_subscriptions, csh_onesignal_client)
send_notification(notification_body, intro_subscriptions, intro_onesignal_client)


def packet_starting_notification(packet):
subscriptions = NotificationSubscription.query.filter_by(freshman_username=packet.freshman_username)
if subscriptions:
notification_body = post_body
notification_body["contents"]["en"] = 'Log into your packet, and get started meeting people!'
notification_body["headings"]["en"] = 'Your packet has begun!'
notification_body["url"] = app.config["PROTOCOL"] + app.config["PACKET_INTRO"]
notification_body["send_after"] = packet.start.strftime("%Y-%m-%d %H:%M:%S")

send_notification(notification_body, subscriptions, intro_onesignal_client)


def packets_starting_notification(start_date):
member_subscriptions = NotificationSubscription.query.filter(NotificationSubscription.member.isnot(None))
if member_subscriptions:
notification_body = post_body
notification_body["contents"]["en"] = 'New packets have started, visit packet to see them!'
notification_body["headings"]["en"] = 'Packets Start Today!'
notification_body["send_after"] = start_date.strftime("%Y-%m-%d %H:%M:%S")

send_notification(notification_body, member_subscriptions, csh_onesignal_client)