From 331ffcd10c4f02055246df7736e619968b89bfd8 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Mon, 16 Dec 2024 17:48:32 +0100 Subject: [PATCH] =?UTF-8?q?Notification=20Mail=20p=C3=BCpscher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BreCal/msg/notification_element.html | 1 + .../BreCal/services/schedule_routines.py | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/server/BreCal/msg/notification_element.html b/src/server/BreCal/msg/notification_element.html index 3a095e8..6b002c3 100644 --- a/src/server/BreCal/msg/notification_element.html +++ b/src/server/BreCal/msg/notification_element.html @@ -6,6 +6,7 @@ + [[notification_text]]
[[text]] diff --git a/src/server/BreCal/services/schedule_routines.py b/src/server/BreCal/services/schedule_routines.py index d751c69..29226cd 100644 --- a/src/server/BreCal/services/schedule_routines.py +++ b/src/server/BreCal/services/schedule_routines.py @@ -77,6 +77,9 @@ def SendEmails(email_dict): This function sends emails to all users in the emaildict """ try: + pooledConnection = getPoolConnection() + commands = pydapper.using(pooledConnection) + conn = smtplib.SMTP(defs.email_credentials["server"], defs.email_credentials["port"]) conn.set_debuglevel(1) conn.ehlo() @@ -113,8 +116,32 @@ def SendEmails(email_dict): # We want to show the following information for each notification: # Ship-name, Arr/Dep/Shift, ETA/ETD, berth + sentinel = object() + shipcall = commands.query_single_or_default("SELECT * FROM shipcall WHERE id = ?id?", sentinel, model=model.Shipcall, param={"id":notification.shipcall_id}) + if shipcall is sentinel: + logging.error(f"Shipcall with id {notification.shipcall_id} not found") + continue + shipcall_type = defs.shipcall_types[shipcall.type] + eta_text = shipcall.eta.strftime("%d.%m.%Y %H:%M") if shipcall.type == 1 else shipcall.etd.strftime("%d.%m.%Y %H:%M") + + ship = commands.query_single_or_default("SELECT * FROM ship WHERE id = ?id?", sentinel, model=model.Ship, param={"id":shipcall.ship_id}) + if ship is sentinel: + logging.error(f"Ship with id {shipcall.ship_id} not found") + continue + berth_id = shipcall.arrival_berth_id if shipcall.type == 1 else shipcall.departure_berth_id + berth = commands.query_single_or_default("SELECT * FROM berth WHERE id = ?id?", sentinel, model=model.Berth, param={"id":berth_id}) + berth_text = "" + if berth is not sentinel: + berth_text = berth.name + times = commands.query_single_or_default("SELECT * FROM times WHERE shipcall_id = ?id? and participant_type = 8", sentinel, model=model.Times, param={"id":notification.shipcall_id}) + if times is not sentinel: + eta_text = times.eta_berth.strftime("%d.%m.%Y %H:%M") if shipcall.type == 1 else times.etd_berth.strftime("%d.%m.%Y %H:%M") + + text = f"{ship.name} ({shipcall_type}) - {eta_text} - {berth_text}" + + element = element.replace("[[text]]", text) + element = element.replace("[[notification_text]]", message_type["msg_text"]) - element = element.replace("[[text]]", message_type["msg_text"]) replacement += element body = body.replace("[[NOTIFICATION_ELEMENTS]]", replacement)