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)