changeset 4285ab9d14f2 in modules/marketing_automation:default
details:
https://hg.tryton.org/modules/marketing_automation?cmd=changeset;node=4285ab9d14f2
description:
Support Genshi expressions in email title
issue9321
review290011002
diffstat:
CHANGELOG | 4 +++-
marketing_automation.py | 25 ++++++++++++++++++++++---
message.xml | 3 +++
setup.py | 2 +-
4 files changed, 29 insertions(+), 5 deletions(-)
diffs (111 lines):
diff -r 0f3118c263b6 -r 4285ab9d14f2 CHANGELOG
--- a/CHANGELOG Mon May 04 12:18:26 2020 +0200
+++ b/CHANGELOG Sat Jul 04 20:07:31 2020 +0200
@@ -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 @@
* 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 -r 0f3118c263b6 -r 4285ab9d14f2 marketing_automation.py
--- a/marketing_automation.py Mon May 04 12:18:26 2020 +0200
+++ b/marketing_automation.py Sat Jul 04 20:07:31 2020 +0200
@@ -19,7 +19,7 @@
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 @@
'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 @@
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 @@
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 @@
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 @@
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 -r 0f3118c263b6 -r 4285ab9d14f2 message.xml
--- a/message.xml Mon May 04 12:18:26 2020 +0200
+++ b/message.xml Sat Jul 04 20:07:31 2020 +0200
@@ -12,6 +12,9 @@
<record model="ir.message" id="msg_activity_invalid_email_template">
<field name="text">Invalid e-mail template in activity
"%(activity)s" with exception "%(exception)s".</field>
</record>
+ <record model="ir.message" id="msg_activity_invalid_email_title">
+ <field name="text">Invalid e-mail title in activity "%(activity)s"
with exception "%(exception)s".</field>
+ </record>
<record model="ir.message" id="msg_activity_record_unique">
<field name="text">Record Activity must be unique by record and
activity.</field>
</record>
diff -r 0f3118c263b6 -r 4285ab9d14f2 setup.py
--- a/setup.py Mon May 04 12:18:26 2020 +0200
+++ b/setup.py Sat Jul 04 20:07:31 2020 +0200
@@ -51,7 +51,7 @@
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))