Skip to content

Commit

Permalink
Enable passing context variable to email notification templates
Browse files Browse the repository at this point in the history
Add argument to provide context variables to `NotificationMessage`
class. Use the context variable to generate email notification
message in `Notification` class.

Signed-off-by: Jeny Sadadia <[email protected]>
  • Loading branch information
Jeny Sadadia committed Sep 18, 2024
1 parent e0001b2 commit e1e4ec7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions kcidb/monitor/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
LOGGER = logging.getLogger(__name__)


class NotificationMessage:
class NotificationMessage: # pylint: disable=too-many-instance-attributes
"""
Message for a notification about a report object state.
"""
# It's OK pylint: disable=too-many-arguments
def __init__(self, to, subject, body, cc=None, bcc=None, id="", due=None):
def __init__(self, to, subject, body, cc=None, bcc=None, id="", due=None,
context=None):
"""
Initialize a notification message.
Expand Down Expand Up @@ -100,6 +101,7 @@ def __init__(self, to, subject, body, cc=None, bcc=None, id="", due=None):
self.bcc = bcc
self.id = id
self.due = due
self.context = context


class Notification:
Expand Down Expand Up @@ -180,6 +182,8 @@ def render(self):
ctx = {
self.obj.get_type().name: self.obj,
}
if self.message.context:
ctx.update(self.message.context)
subject = TEMPLATE_ENV.from_string(self.message.subject).render(ctx)
subject_extra_characters = \
len(subject) - NOTIFICATION_MESSAGE_SUBJECT_MAX_LEN
Expand Down

0 comments on commit e1e4ec7

Please sign in to comment.