From 5f2361fe7aac87df0d3bb7b32b32b28077340443 Mon Sep 17 00:00:00 2001 From: Devin Matte Date: Tue, 20 Aug 2019 23:18:41 -0400 Subject: [PATCH 1/3] Starting notifications --- packet/commands.py | 3 +++ packet/notifications.py | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packet/commands.py b/packet/commands.py index 4237c61f..434850a1 100644 --- a/packet/commands.py +++ b/packet/commands.py @@ -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, \ @@ -132,6 +133,8 @@ def create_packets(freshmen_csv): packet = Packet(freshman=freshman, start=start, end=end) db.session.add(packet) send_start_packet_mail(packet) + packet_starting_notification(packet) + packets_starting_notification(start) for member in all_upper: sig = UpperSignature(packet=packet, member=member.uid) diff --git a/packet/notifications.py b/packet/notifications.py index 8d11449b..907dc9c5 100644 --- a/packet/notifications.py +++ b/packet/notifications.py @@ -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!' @@ -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 + + 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) From 22da9ac2b52691d55b004ef7ee02113f242fda76 Mon Sep 17 00:00:00 2001 From: Devin Matte Date: Tue, 20 Aug 2019 23:20:06 -0400 Subject: [PATCH 2/3] Fixing datetime formating --- packet/notifications.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packet/notifications.py b/packet/notifications.py index 907dc9c5..5eea9d73 100644 --- a/packet/notifications.py +++ b/packet/notifications.py @@ -57,7 +57,7 @@ def packet_starting_notification(packet): 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 + notification_body["send_after"] = packet.start.strftime("%Y-%m-%d %H:%M:%S") send_notification(notification_body, subscriptions, intro_onesignal_client) From eed9e79c1bce75a7fb6b530c48fdf6b09fea2628 Mon Sep 17 00:00:00 2001 From: Devin Matte Date: Tue, 20 Aug 2019 23:49:48 -0400 Subject: [PATCH 3/3] Single notification for starting --- packet/commands.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packet/commands.py b/packet/commands.py index 434850a1..ccfc8e3a 100644 --- a/packet/commands.py +++ b/packet/commands.py @@ -126,6 +126,9 @@ 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...") @@ -134,7 +137,6 @@ def create_packets(freshmen_csv): db.session.add(packet) send_start_packet_mail(packet) packet_starting_notification(packet) - packets_starting_notification(start) for member in all_upper: sig = UpperSignature(packet=packet, member=member.uid)