diff --git a/CHANGELOG b/CHANGELOG
index 129a65fd29..91333d2df6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Support Genshi expressions in email title
+
Version 5.6.0 - 2020-05-04
* Bug fixes (see mercurial logs for details)
@@ -5,4 +7,4 @@ Version 5.4.0 - 2019-11-04
* Bug fixes (see mercurial logs for details)
Version 5.2.0 - 2019-05-06
-* Initial release
\ No newline at end of file
+* Initial release
diff --git a/marketing_automation.py b/marketing_automation.py
index 31ac5f7d4c..73c61b6b33 100644
--- a/marketing_automation.py
+++ b/marketing_automation.py
@@ -19,7 +19,7 @@ except ImportError:
from sql import Literal
from sql.aggregate import Count
from sql.functions import Substring, Position
-from genshi.template import MarkupTemplate
+from genshi.template import MarkupTemplate, TextTemplate
from genshi.core import START, END, QName, Attrs
from trytond.config import config
@@ -315,7 +315,10 @@ class Activity(ModelSQL, ModelView):
'invisible': Eval('action') != 'send_email',
'required': Eval('action') == 'send_email',
},
- depends=['action'])
+ depends=['action'],
+ help="The subject of the email.\n"
+ "The Genshi syntax can be used "
+ "with 'record' in the evaluation context.")
email_template = fields.Text(
"E-Mail Template",
translate=True,
@@ -445,6 +448,7 @@ class Activity(ModelSQL, ModelView):
super().validate(activities)
for activity in activities:
activity.check_condition()
+ activity.check_email_title()
activity.check_email_template()
def check_condition(self):
@@ -471,6 +475,18 @@ class Activity(ModelSQL, ModelView):
activity=self.rec_name,
exception=exception)) from exception
+ def check_email_title(self):
+ if not self.email_title:
+ return
+ try:
+ TextTemplate(self.email_title)
+ except Exception as exception:
+ raise TemplateError(
+ gettext('marketing_automation'
+ '.msg_activity_invalid_email_title',
+ activity=self.rec_name,
+ exception=exception)) from exception
+
def execute(self, activity, **kwargs):
pool = Pool()
RecordActivity = pool.get('marketing.automation.record.activity')
@@ -569,6 +585,9 @@ class Activity(ModelSQL, ModelView):
yield END, QName('img'), pos
yield kind, data, pos
+ title = (TextTemplate(translated.email_title)
+ .generate(record=record.record)
+ .render())
template = MarkupTemplate(translated.email_template)
content = (template
.generate(record=record.record)
@@ -578,7 +597,7 @@ class Activity(ModelSQL, ModelView):
msg = MIMEMultipart('alternative')
msg['From'] = self.email_from or config.get('email', 'from')
msg['To'] = to
- msg['Subject'] = Header(translated.email_title, 'utf-8')
+ msg['Subject'] = Header(title, 'utf-8')
if html2text:
converter = html2text.HTML2Text()
part = MIMEText(
diff --git a/message.xml b/message.xml
index a2b4d2e7ca..a00ee5067e 100644
--- a/message.xml
+++ b/message.xml
@@ -12,6 +12,9 @@ this repository contains the full copyright notices and license terms. -->
Invalid e-mail template in activity "%(activity)s" with exception "%(exception)s".
+
+ Invalid e-mail title in activity "%(activity)s" with exception "%(exception)s".
+
Record Activity must be unique by record and activity.
diff --git a/setup.py b/setup.py
index 6ec618a9a7..b06d416013 100755
--- a/setup.py
+++ b/setup.py
@@ -51,7 +51,7 @@ for build in ['CI_BUILD_NUMBER', 'CI_JOB_NUMBER', 'CI_JOB_ID']:
if local_version:
version += '+' + '.'.join(local_version)
-requires = ['werkzeug']
+requires = ['werkzeug', 'Genshi']
for dep in info.get('depends', []):
if not re.match(r'(ir|res)(\W|$)', dep):
requires.append(get_require_version('trytond_%s' % dep))