From 5382bde82c8f8bd49ceb6f082c9382defc59f225 Mon Sep 17 00:00:00 2001 From: tfo Date: Thu, 2 Jan 2020 11:23:57 +0100 Subject: [PATCH] [IMP] email_template_qweb: black, isort --- email_template_qweb/__manifest__.py | 20 +++------- email_template_qweb/models/mail_template.py | 38 +++++++++---------- email_template_qweb/readme/CONTRIBUTORS.rst | 2 +- email_template_qweb/readme/DESCRIPTION.rst | 2 +- .../tests/test_mail_template_qweb.py | 16 ++++---- 5 files changed, 33 insertions(+), 45 deletions(-) diff --git a/email_template_qweb/__manifest__.py b/email_template_qweb/__manifest__.py index ab816c1ae..3d5244511 100644 --- a/email_template_qweb/__manifest__.py +++ b/email_template_qweb/__manifest__.py @@ -3,21 +3,13 @@ { "name": "QWeb for email templates", "version": "12.0.1.0.0", - "author": "Therp BV, " - "Odoo Community Association (OCA)", + "author": "Therp BV, Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Marketing", "summary": "Use the QWeb templating mechanism for emails", - 'website': 'https://github.com/OCA/social', - "depends": [ - 'mail', - ], - "demo": [ - "demo/ir_ui_view.xml", - "demo/mail_template.xml", - ], - "data": [ - "views/mail_template.xml", - ], - 'installable': True, + "website": "https://github.com/OCA/social", + "depends": ["mail"], + "demo": ["demo/ir_ui_view.xml", "demo/mail_template.xml"], + "data": ["views/mail_template.xml"], + "installable": True, } diff --git a/email_template_qweb/models/mail_template.py b/email_template_qweb/models/mail_template.py index 0f87a0825..a143e7590 100644 --- a/email_template_qweb/models/mail_template.py +++ b/email_template_qweb/models/mail_template.py @@ -1,17 +1,21 @@ # Copyright 2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import api, fields, tools, models +from odoo import api, fields, models, tools class MailTemplate(models.Model): - _inherit = 'mail.template' + _inherit = "mail.template" body_type = fields.Selection( - [('jinja2', 'Jinja2'), ('qweb', 'QWeb')], 'Body templating engine', - default='jinja2', required=True) + [("jinja2", "Jinja2"), ("qweb", "QWeb")], + "Body templating engine", + default="jinja2", + required=True, + ) body_view_id = fields.Many2one( - 'ir.ui.view', 'Body view', domain=[('type', '=', 'qweb')]) - body_view_arch = fields.Text(related='body_view_id.arch') + "ir.ui.view", "Body view", domain=[("type", "=", "qweb")] + ) + body_view_arch = fields.Text(related="body_view_id.arch") @api.multi def generate_email(self, res_ids, fields=None): @@ -19,24 +23,18 @@ class MailTemplate(models.Model): if isinstance(res_ids, int): res_ids = [res_ids] multi_mode = False - result = super(MailTemplate, self).generate_email( - res_ids, fields=fields - ) + result = super(MailTemplate, self).generate_email(res_ids, fields=fields) for res_id, template in self.get_email_template(res_ids).items(): - if template.body_type == 'qweb' and\ - (not fields or 'body_html' in fields): + if template.body_type == "qweb" and (not fields or "body_html" in fields): for record in self.env[template.model].browse(res_id): - body_html = template.body_view_id.render({ - 'object': record, - 'email_template': template, - }) + body_html = template.body_view_id.render( + {"object": record, "email_template": template} + ) # Some wizards, like when sending a sales order, need this # fix to display accents correctly body_html = tools.ustr(body_html) - result[res_id]['body_html'] = self.render_post_process( - body_html - ) - result[res_id]['body'] = tools.html_sanitize( - result[res_id]['body_html'] + result[res_id]["body_html"] = self.render_post_process(body_html) + result[res_id]["body"] = tools.html_sanitize( + result[res_id]["body_html"] ) return multi_mode and result or result[res_ids[0]] diff --git a/email_template_qweb/readme/CONTRIBUTORS.rst b/email_template_qweb/readme/CONTRIBUTORS.rst index e19a18721..2349a885d 100644 --- a/email_template_qweb/readme/CONTRIBUTORS.rst +++ b/email_template_qweb/readme/CONTRIBUTORS.rst @@ -3,4 +3,4 @@ * Carlos Lopez Mite * `Tecnativa `_: - * Ernesto Tejeda \ No newline at end of file + * Ernesto Tejeda diff --git a/email_template_qweb/readme/DESCRIPTION.rst b/email_template_qweb/readme/DESCRIPTION.rst index b216735ec..71f9ece9d 100644 --- a/email_template_qweb/readme/DESCRIPTION.rst +++ b/email_template_qweb/readme/DESCRIPTION.rst @@ -1,5 +1,5 @@ This module was written to allow you to write email templates in QWeb instead of jinja2. The advantage here is that with QWeb, you can make use of inheritance and the ``call`` statement, which allows you to reuse designs and -snippets in multiple templates, making your development process simpler. +snippets in multiple templates, making your development process simpler. Furthermore, QWeb views are easier to edit with the integrated ACE editor. diff --git a/email_template_qweb/tests/test_mail_template_qweb.py b/email_template_qweb/tests/test_mail_template_qweb.py index 6f789d486..36ecaef26 100644 --- a/email_template_qweb/tests/test_mail_template_qweb.py +++ b/email_template_qweb/tests/test_mail_template_qweb.py @@ -5,21 +5,19 @@ from odoo.tests.common import TransactionCase class TestMailTemplateQweb(TransactionCase): def test_email_template_qweb(self): - template = self.env.ref('email_template_qweb.email_template_demo1') + template = self.env.ref("email_template_qweb.email_template_demo1") mail_values = template.generate_email([self.env.user.id]) self.assertTrue( # this comes from the called template if everything worked - '