Support Genshi expressions in email title
issue9321 review290011002
This commit is contained in:
@@ -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
|
||||
* Initial release
|
||||
|
||||
+22
-3
@@ -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(
|
||||
|
||||
@@ -12,6 +12,9 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<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>
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user