From fa8f47e0d1b44dbbe600d518d412d6b1c43190bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 30 Nov 2023 10:07:57 +0100 Subject: [PATCH] Add short method to email marketing template context This allows dynamic URL to be shorten and tracked. Closes #12785 --- modules/marketing_automation/marketing_automation.py | 2 ++ modules/marketing_email/marketing.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/marketing_automation/marketing_automation.py b/modules/marketing_automation/marketing_automation.py index b608b1fb3c..2ad87d6320 100644 --- a/modules/marketing_automation/marketing_automation.py +++ b/modules/marketing_automation/marketing_automation.py @@ -9,6 +9,7 @@ from email.header import Header from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.utils import formataddr, getaddresses +from functools import partial from urllib.parse import ( parse_qsl, quote, urlencode, urljoin, urlsplit, urlunsplit) @@ -593,6 +594,7 @@ class Activity(ModelSQL, ModelView): yield kind, data, pos context = self.email_context(record) + context['short'] = partial(short, event='on_email_clicked') title = (TextTemplate(translated.email_title) .generate(**context) .render()) diff --git a/modules/marketing_email/marketing.py b/modules/marketing_email/marketing.py index b452bda5c5..bcc6422942 100644 --- a/modules/marketing_email/marketing.py +++ b/modules/marketing_email/marketing.py @@ -7,7 +7,7 @@ from email.header import Header from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.utils import formataddr, getaddresses -from functools import lru_cache +from functools import lru_cache, partial from urllib.parse import ( parse_qs, parse_qsl, urlencode, urljoin, urlsplit, urlunsplit) @@ -508,7 +508,9 @@ class Message(Workflow, ModelSQL, ModelView): template = MarkupTemplate(message.content) for email in (emails or message.list_.emails): content = (template - .generate(email=email) + .generate( + email=email, + short=partial(short, record=message)) .filter(convert_href(message)) .render())