summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYannick Tivisse <yti@odoo.com>2018-10-01 17:26:32 +0200
committerYannick Tivisse <yti@odoo.com>2018-10-02 12:35:34 +0200
commit532d82a7a9952c5ee843f91e63aae1ca986c6c9d (patch)
tree687d28b385891b1ea6bd37e71267f2bb26a5597e
parentb2b9545cf38855fdb97e992aa2883cdab6909e96 (diff)
[IMP] mail: Make mail.compose.message code more readable
Purpose ======= Remove the method 'render_template' in mail.compose.message as the indirection is not useful. Call the method on the correct model (mail.template) directly.
-rw-r--r--addons/digest/models/digest.py2
-rw-r--r--addons/gamification/models/challenge.py4
-rw-r--r--addons/gamification/models/goal.py2
-rw-r--r--addons/l10n_ch/models/mail_template.py2
-rw-r--r--addons/mail/models/mail_template.py8
-rw-r--r--addons/mail/wizard/mail_compose_message.py12
-rw-r--r--addons/website_slides/models/slides.py4
7 files changed, 15 insertions, 19 deletions
diff --git a/addons/digest/models/digest.py b/addons/digest/models/digest.py
index 7dc03b405a6..9446f5454a2 100644
--- a/addons/digest/models/digest.py
+++ b/addons/digest/models/digest.py
@@ -135,7 +135,7 @@ class Digest(models.Model):
return False
tip.user_ids = [4, user.id]
body = tools.html_sanitize(tip.tip_description)
- tip_description = self.env['mail.template'].render_template(body, 'digest.tip', self.id)
+ tip_description = self.env['mail.template']._render_template(body, 'digest.tip', self.id)
return tip_description
def compute_kpis_actions(self, company, user):
diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py
index bf8e17fa4a2..dae80246da1 100644
--- a/addons/gamification/models/challenge.py
+++ b/addons/gamification/models/challenge.py
@@ -545,7 +545,7 @@ class Challenge(models.Model):
if challenge.visibility_mode == 'ranking':
lines_boards = challenge._get_serialized_challenge_lines(restrict_goals=subset_goals)
- body_html = MailTemplates.with_context(challenge_lines=lines_boards).render_template(challenge.report_template_id.body_html, 'gamification.challenge', challenge.id)
+ body_html = MailTemplates.with_context(challenge_lines=lines_boards)._render_template(challenge.report_template_id.body_html, 'gamification.challenge', challenge.id)
# send to every follower and participant of the challenge
challenge.message_post(
@@ -566,7 +566,7 @@ class Challenge(models.Model):
if not lines:
continue
- body_html = MailTemplates.sudo(user).with_context(challenge_lines=lines).render_template(
+ body_html = MailTemplates.sudo(user).with_context(challenge_lines=lines)._render_template(
challenge.report_template_id.body_html,
'gamification.challenge',
challenge.id)
diff --git a/addons/gamification/models/goal.py b/addons/gamification/models/goal.py
index a812764e5c6..a44d562500b 100644
--- a/addons/gamification/models/goal.py
+++ b/addons/gamification/models/goal.py
@@ -221,7 +221,7 @@ class Goal(models.Model):
template = self.env.ref('gamification.email_template_goal_reminder')\
.get_email_template(self.id)
body_html = self.env['mail.template'].with_context(template._context)\
- .render_template(template.body_html, 'gamification.goal', self.id)
+ ._render_template(template.body_html, 'gamification.goal', self.id)
self.env['mail.thread'].message_post(
body=body_html,
partner_ids=[self.user_id.partner_id.id],
diff --git a/addons/l10n_ch/models/mail_template.py b/addons/l10n_ch/models/mail_template.py
index 802ec7a4d91..b089d0b5f86 100644
--- a/addons/l10n_ch/models/mail_template.py
+++ b/addons/l10n_ch/models/mail_template.py
@@ -32,7 +32,7 @@ class MailTemplate(models.Model):
if related_model._name == 'account.invoice' and related_model.l10n_ch_isr_valid:
#We add an attachment containing the ISR
template = res_ids_to_templates[res_id]
- report_name = 'ISR-' + self.render_template(template.report_name, template.model, res_id) + '.pdf'
+ report_name = 'ISR-' + self._render_template(template.report_name, template.model, res_id) + '.pdf'
pdf = self.env.ref('l10n_ch.l10n_ch_isr_report').render_qweb_pdf([res_id])[0]
pdf = base64.b64encode(pdf)
diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py
index f3286e66599..4f3689ba99b 100644
--- a/addons/mail/models/mail_template.py
+++ b/addons/mail/models/mail_template.py
@@ -289,7 +289,7 @@ class MailTemplate(models.Model):
return html
@api.model
- def render_template(self, template_txt, model, res_ids, post_process=False):
+ def _render_template(self, template_txt, model, res_ids, post_process=False):
""" Render the given template text, replace mako expressions ``${expr}``
with the result of evaluating these expressions with an evaluation
context containing:
@@ -361,7 +361,7 @@ class MailTemplate(models.Model):
return results
self.ensure_one()
- langs = self.render_template(self.lang, self.model, res_ids)
+ langs = self._render_template(self.lang, self.model, res_ids)
for res_id, lang in langs.items():
if lang:
template = self.with_context(lang=lang)
@@ -434,7 +434,7 @@ class MailTemplate(models.Model):
Template = Template.with_context(lang=template._context.get('lang'))
for field in fields:
Template = Template.with_context(safe=field in {'subject'})
- generated_field_values = Template.render_template(
+ generated_field_values = Template._render_template(
getattr(template, field), template.model, template_res_ids,
post_process=(field == 'body_html'))
for res_id, field_value in generated_field_values.items():
@@ -465,7 +465,7 @@ class MailTemplate(models.Model):
if template.report_template:
for res_id in template_res_ids:
attachments = []
- report_name = self.render_template(template.report_name, template.model, res_id)
+ report_name = self._render_template(template.report_name, template.model, res_id)
report = template.report_template
report_service = report.report_name
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py
index bf794fc2a7f..bac7148ca9c 100644
--- a/addons/mail/wizard/mail_compose_message.py
+++ b/addons/mail/wizard/mail_compose_message.py
@@ -458,10 +458,10 @@ class MailComposer(models.TransientModel):
multi_mode = False
res_ids = [res_ids]
- subjects = self.render_template(self.subject, self.model, res_ids)
- bodies = self.render_template(self.body, self.model, res_ids, post_process=True)
- emails_from = self.render_template(self.email_from, self.model, res_ids)
- replies_to = self.render_template(self.reply_to, self.model, res_ids)
+ subjects = self.env['mail.template']._render_template(self.subject, self.model, res_ids)
+ bodies = self.env['mail.template']._render_template(self.body, self.model, res_ids, post_process=True)
+ emails_from = self.env['mail.template']._render_template(self.email_from, self.model, res_ids)
+ replies_to = self.env['mail.template']._render_template(self.reply_to, self.model, res_ids)
default_recipients = {}
if not self.partner_ids:
default_recipients = self.env['mail.thread'].message_get_default_recipients(res_model=self.model, res_ids=res_ids)
@@ -520,7 +520,3 @@ class MailComposer(models.TransientModel):
values[res_id] = res_id_values
return multi_mode and values or values[res_ids[0]]
-
- @api.model
- def render_template(self, template, model, res_ids, post_process=False):
- return self.env['mail.template'].render_template(template, model, res_ids, post_process=post_process)
diff --git a/addons/website_slides/models/slides.py b/addons/website_slides/models/slides.py
index 186973cec6d..ab8494d1212 100644
--- a/addons/website_slides/models/slides.py
+++ b/addons/website_slides/models/slides.py
@@ -492,8 +492,8 @@ class Slide(models.Model):
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
for slide in self.filtered(lambda slide: slide.website_published and slide.channel_id.publish_template_id):
publish_template = slide.channel_id.publish_template_id
- html_body = publish_template.with_context(base_url=base_url).render_template(publish_template.body_html, 'slide.slide', slide.id)
- subject = publish_template.render_template(publish_template.subject, 'slide.slide', slide.id)
+ html_body = publish_template.with_context(base_url=base_url)._render_template(publish_template.body_html, 'slide.slide', slide.id)
+ subject = publish_template._render_template(publish_template.subject, 'slide.slide', slide.id)
slide.channel_id.message_post(
subject=subject,
body=html_body,