From 4bebbfdcf5e50643f136c7b297697715fa6b3087 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 10 Dec 2015 16:01:03 +0100 Subject: [PATCH] [FIX] mail: jinja2 code compatible with wysiwyg for notifications When editing an email template with the wysiwyg, the `<` and `>` operators are automatically converted to `<` and `>`, even for the Jinja2 conditions, therefore breaking these conditions, and the render of the email templates. We avoid to use these operators in the email template, so users can customize the notification email template without having an advanced knowledge on how to edit an email template containing Jinja2 code. Besides, the line return at the end of the email template, just after the `% endif`, is done on purpose as well: the wysiwyg adds automatically, at the time of this revision, `

` at the end of the email template source, but this cannot be added on the same line than `% endif`, otherwise this is considered as Jinja2 code, and it's not. opw-659113 --- addons/mail/data/mail_data.xml | 10 ++++++---- addons/mail/models/mail_template.py | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/mail/data/mail_data.xml b/addons/mail/data/mail_data.xml index 2b2f389726b..327c776b987 100644 --- a/addons/mail/data/mail_data.xml +++ b/addons/mail/data/mail_data.xml @@ -83,7 +83,7 @@ % endif % if not ctx.get('button_access') and not ctx.get('button_follow') and not ctx.get('button_unfollow') and ctx.get('model_name'): -

+

About ${ctx['model_name']} % if ctx.get('record_name'): : ${ctx['record_name']} @@ -97,7 +97,7 @@ % if ctx.get('actions'): % for action in ctx['actions']: ${action['title']} - %if len(ctx['actions']) > 1 and loop.index < len(ctx['actions']): + %if cmp(len(ctx['actions']), 1) == 1 and cmp(len(ctx['actions']), loop.index) == 1: | % endif % endfor @@ -113,6 +113,7 @@ using Odoo % endif +

@@ -136,7 +137,7 @@ % if ctx.get('tracking'): % endif @@ -154,7 +155,8 @@ -% endif]]> +% endif +]]> diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index 19aee797c3b..3117b571ed6 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -77,6 +77,7 @@ try: 'reduce': reduce, 'map': map, 'round': round, + 'cmp': cmp, # dateutil.relativedelta is an old-style class and cannot be directly # instanciated wihtin a jinja2 expression, so a lambda "proxy" is