Skip to content

Commit 5f2361f

Browse files
committed
Starting notifications
1 parent 7147d85 commit 5f2361f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packet/commands.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import click
99

1010
from packet.mail import send_start_packet_mail
11+
from packet.notifications import packet_starting_notification, packets_starting_notification
1112
from . import app, db
1213
from .models import Freshman, Packet, FreshSignature, UpperSignature, MiscSignature
1314
from .ldap import ldap_get_eboard_role, ldap_get_active_rtps, ldap_get_3das, ldap_get_webmasters, \
@@ -132,6 +133,8 @@ def create_packets(freshmen_csv):
132133
packet = Packet(freshman=freshman, start=start, end=end)
133134
db.session.add(packet)
134135
send_start_packet_mail(packet)
136+
packet_starting_notification(packet)
137+
packets_starting_notification(start)
135138

136139
for member in all_upper:
137140
sig = UpperSignature(packet=packet, member=member.uid)

packet/notifications.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def packet_signed_notification(packet, signer):
3939
def packet_100_percent_notification(packet):
4040
member_subscriptions = NotificationSubscription.query.filter(NotificationSubscription.member.isnot(None))
4141
intro_subscriptions = NotificationSubscription.query.filter(NotificationSubscription.freshman_username.isnot(None))
42-
4342
if member_subscriptions or intro_subscriptions:
4443
notification_body = post_body
4544
notification_body["contents"]["en"] = packet.freshman.name + ' got 💯 on packet!'
@@ -49,3 +48,26 @@ def packet_100_percent_notification(packet):
4948

5049
send_notification(notification_body, member_subscriptions, csh_onesignal_client)
5150
send_notification(notification_body, intro_subscriptions, intro_onesignal_client)
51+
52+
53+
def packet_starting_notification(packet):
54+
subscriptions = NotificationSubscription.query.filter_by(freshman_username=packet.freshman_username)
55+
if subscriptions:
56+
notification_body = post_body
57+
notification_body["contents"]["en"] = 'Log into your packet, and get started meeting people!'
58+
notification_body["headings"]["en"] = 'Your packet has begun!'
59+
notification_body["url"] = app.config["PROTOCOL"] + app.config["PACKET_INTRO"]
60+
notification_body["send_after"] = packet.start
61+
62+
send_notification(notification_body, subscriptions, intro_onesignal_client)
63+
64+
65+
def packets_starting_notification(start_date):
66+
member_subscriptions = NotificationSubscription.query.filter(NotificationSubscription.member.isnot(None))
67+
if member_subscriptions:
68+
notification_body = post_body
69+
notification_body["contents"]["en"] = 'New packets have started, visit packet to see them!'
70+
notification_body["headings"]["en"] = 'Packets Start Today!'
71+
notification_body["send_after"] = start_date.strftime("%Y-%m-%d %H:%M:%S")
72+
73+
send_notification(notification_body, member_subscriptions, csh_onesignal_client)

0 commit comments

Comments
 (0)