Skip to content

Commit 2e431b2

Browse files
committed
Add email template
1 parent 4156a47 commit 2e431b2

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/scaup/models/alerts.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ruff: noqa: E501
22

3+
from string import Template
4+
35
EMAIL_HEADER = """
46
<html>
57
<body>
@@ -13,3 +15,18 @@
1315
EMAIL_FOOTER = """
1416
<p style="border-top: 1px solid #001d55; background-color: #1040A1; padding: 10px; color: white;">© 2025, Diamond Light Source</p></div>
1517
"""
18+
19+
ALERT_BODY = Template("""
20+
<p>Dear $local_contact,</p>
21+
22+
<p>The user(s) have submitted important information regarding the grids and pre-session data collection parameters for session $proposal-$session in SCAUP.</p>
23+
24+
<p>To view this information, please <a href="$frontend_url/proposals/$proposal/session/$session">go to the Session Samples Dashboard page for the session</a>, select a shipment, and select “Print contents as table” under the Actions section</p>
25+
26+
<p>Before starting an EPU session, please ensure that grids are added to the Cassette positions in the Sample Collection Summary page. This step allows results from the auto-processing pipeline in PATo to be correctly linked to sample conditions in SCAUP.</p>
27+
28+
<p>Note: If you are not the designated Local Contact for this session, kindly forward this email to the appropriate person.</p>
29+
30+
<p>Many thanks,</p>
31+
<p>SCAUP team</p>
32+
""")

src/scaup/utils/alerts.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from ..assets.paths import COMPANY_LOGO_LIGHT
1818
from ..models.alerts import (
19+
ALERT_BODY,
1920
EMAIL_FOOTER,
2021
EMAIL_HEADER,
2122
)
@@ -119,13 +120,18 @@ def alert_session_lcs():
119120
)
120121

121122
for session in upcoming_sessions:
122-
msg = create_email(
123-
"This is a placeholder email body",
124-
f"Session {session.reference} starting in 24 hours",
125-
)
126-
127123
for local_contact in session.local_contacts:
128124
if local_contact in Config.alerts.local_contacts:
125+
msg = create_email(
126+
ALERT_BODY.safe_substitute(
127+
local_contact=local_contact,
128+
proposal=f"{session.reference.code}{session.reference.number}",
129+
session=session.reference.visit_number,
130+
frontend_url=Config.frontend_url,
131+
),
132+
f"Session {session.reference} - Grids and Pre-Session Data Collection Parameters in SCAUP ",
133+
)
134+
129135
recipient = Config.alerts.local_contacts[local_contact]
130136
try:
131137
with SMTP(Config.alerts.smtp_server, Config.alerts.smtp_port, timeout=10) as smtp:
@@ -136,6 +142,10 @@ def alert_session_lcs():
136142

137143
smtp.sendmail(Config.alerts.contact_email, recipient, msg.as_string())
138144

139-
app_logger.info("%s received email for session %s", recipient, session.reference)
145+
app_logger.info(
146+
"%s received email for session %s",
147+
recipient,
148+
session.reference,
149+
)
140150
except Exception as e:
141151
app_logger.error("Error while sending alert email to %s: %s", recipient, e)

0 commit comments

Comments
 (0)