Bugfix for last update

This commit is contained in:
Daniel Schick 2025-03-05 17:39:39 +01:00
parent a1b807824e
commit c8550431e0

View File

@ -114,11 +114,11 @@ def SendEmails(email_dict):
defs.message_types = json.load(f) defs.message_types = json.load(f)
f.close() f.close()
for user, notifications in email_dict.items(): for user_email, notifications in email_dict.items():
msg = EmailMessage() msg = EmailMessage()
msg["Subject"] = '[Bremen calling] Notification' msg["Subject"] = '[Bremen calling] Notification'
msg["From"] = defs.email_credentials["sender"] msg["From"] = defs.email_credentials["sender"]
msg["To"] = user["user_email"] msg["To"] = user_email
with open(os.path.join(current_path,'../msg/notification_template.html'), mode="r", encoding="utf-8") as file: with open(os.path.join(current_path,'../msg/notification_template.html'), mode="r", encoding="utf-8") as file:
body = file.read() body = file.read()
@ -170,7 +170,7 @@ def SendEmails(email_dict):
body = body.replace("[[NOTIFICATION_ELEMENTS]]", replacement) body = body.replace("[[NOTIFICATION_ELEMENTS]]", replacement)
msg.set_content(body, subtype='html', charset='utf-8', cte='8bit') msg.set_content(body, subtype='html', charset='utf-8', cte='8bit')
conn.sendmail(defs.email_credentials["sender"], user["user_email"], msg.as_string()) conn.sendmail(defs.email_credentials["sender"], user_email, msg.as_string())
except Exception as ex: except Exception as ex:
logging.error(ex) logging.error(ex)
@ -212,13 +212,15 @@ def SendNotifications():
p_query = "SELECT * from shipcall_participant_map where shipcall_id = ?id?" p_query = "SELECT * from shipcall_participant_map where shipcall_id = ?id?"
assigned_participants = commands.query(p_query, model=model.ShipcallParticipantMap, param={"id":notification.shipcall_id}) assigned_participants = commands.query(p_query, model=model.ShipcallParticipantMap, param={"id":notification.shipcall_id})
for assigned_participant in assigned_participants: for assigned_participant in assigned_participants:
if not assigned_participant.participant_id in users_dict:
continue
users = users_dict[assigned_participant.participant_id] users = users_dict[assigned_participant.participant_id]
for user in users: for user in users:
# send notification to user # send notification to user
if user["notify_email"]: if user["notify_email"]:
if user not in email_dict: if user["user_email"] not in email_dict:
email_dict[user] = [] email_dict[user["user_email"]] = []
email_dict[user].append(notification) email_dict[user["user_email"]].append(notification)
if user["notify_whatsapp"]: if user["notify_whatsapp"]:
# TBD # TBD
pass pass
@ -226,14 +228,15 @@ def SendNotifications():
# TBD # TBD
pass pass
else: else:
if notification.participant_id in users_dict:
users = users_dict[notification.participant_id] users = users_dict[notification.participant_id]
for user in users: for user in users:
user_notifications = model.bitflag_to_list(user["notify_event"]) user_notifications = model.bitflag_to_list(user["notify_event"])
# send notification to user # send notification to user
if user["notify_email"] and notification.type in user_notifications: if user["notify_email"] and notification.type in user_notifications:
if user not in email_dict: if user["user_email"] not in email_dict:
email_dict[user] = [] email_dict[user["user_email"]] = []
email_dict[user].append(notification) email_dict[user["user_email"]].append(notification)
if user["notify_whatsapp"] and notification.type in user_notifications: if user["notify_whatsapp"] and notification.type in user_notifications:
# TBD # TBD
pass pass