From eee1b39806028fb4f5966fa7a17337f3af600b37 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 13 Mar 2018 15:19:42 +0100 Subject: [PATCH] [FIX] ir_qweb: post process the attributes in widget html value issue: Blog doe not use the cdn because the widget html value is not compiled by the qweb and does not use the attribute post processing. --- addons/website/tests/template_qweb_test.xml | 3 +++ addons/website/tests/test_qweb.py | 27 +++++++++++++++++---- odoo/addons/base/ir/ir_qweb/fields.py | 14 ++++++++++- odoo/addons/base/ir/ir_qweb/ir_qweb.py | 5 ++++ odoo/addons/base/ir/ir_qweb/qweb.py | 2 +- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/addons/website/tests/template_qweb_test.xml b/addons/website/tests/template_qweb_test.xml index ad92b6966e6..423c8d3212e 100644 --- a/addons/website/tests/template_qweb_test.xml +++ b/addons/website/tests/template_qweb_test.xml @@ -26,6 +26,9 @@ x x + xxx +
+
diff --git a/addons/website/tests/test_qweb.py b/addons/website/tests/test_qweb.py index a0423e025ad..e73083a66b2 100644 --- a/addons/website/tests/test_qweb.py +++ b/addons/website/tests/test_qweb.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import re + from odoo import tools from odoo.modules.module import get_module_resource from odoo.tests.common import TransactionCase @@ -22,18 +24,24 @@ class TestQweb(TransactionCase): }) demo = self.env['res.users'].search([('login', '=', 'demo')])[0] + demo.write({"signature": ''' + span + '''}) + demo_env = self.env(user=demo) - html = demo_env['ir.qweb'].render('website.test_template', {}, website_id= website.id) + html = demo_env['ir.qweb'].render('website.test_template', {"user": demo}, website_id= website.id) + html = html.strip().decode('utf8') + html = re.sub(r'\?unique=[^"]+', '', html).encode('utf8') attachments = demo_env['ir.attachment'].search([('url', '=like', '/web/content/%-%/website.test_bundle.%')]) - self.assertEquals(len(attachments), 2) - self.assertEqual(html.strip(), """ + self.assertEqual(len(attachments), 2) + self.assertEqual(html, (""" - + @@ -44,5 +52,14 @@ class TestQweb(TransactionCase): x x + xxx +
+ span +
+
-""" % {"js": attachments[0].url, "css": attachments[1].url}) +""" % { + "js": attachments[0].url, + "css": attachments[1].url, + "user_id": demo.id, + }).encode('utf8')) diff --git a/odoo/addons/base/ir/ir_qweb/fields.py b/odoo/addons/base/ir/ir_qweb/fields.py index b71966e6d6f..1f4475824bc 100644 --- a/odoo/addons/base/ir/ir_qweb/fields.py +++ b/odoo/addons/base/ir/ir_qweb/fields.py @@ -6,6 +6,8 @@ from io import BytesIO from odoo import api, fields, models, _ from PIL import Image import babel +from lxml import etree + from odoo.tools import html_escape as escape, posix_to_ldml, safe_eval, float_utils, format_date, pycompat import logging @@ -252,7 +254,17 @@ class HTMLConverter(models.AbstractModel): @api.model def value_to_html(self, value, options): - return pycompat.to_text(value) + irQweb = self.env['ir.qweb'] + # wrap value inside a body and parse it as HTML + body = etree.fromstring("%s" % value, etree.HTMLParser(encoding='utf-8'))[0] + # use pos processing for all nodes with attributes + for element in body.iter(): + if element.attrib: + attrib = OrderedDict(element.attrib) + attrib = irQweb._post_processing_att(element.tag, attrib, options) + element.attrib.clear() + element.attrib.update(attrib) + return etree.tostring(body, encoding='unicode', method='html')[6:-7] class ImageConverter(models.AbstractModel): diff --git a/odoo/addons/base/ir/ir_qweb/ir_qweb.py b/odoo/addons/base/ir/ir_qweb/ir_qweb.py index 555f5d4eaa7..543029d5f82 100644 --- a/odoo/addons/base/ir/ir_qweb/ir_qweb.py +++ b/odoo/addons/base/ir/ir_qweb/ir_qweb.py @@ -341,6 +341,11 @@ class IrQWeb(models.AbstractModel, QWeb): def _get_field(self, record, field_name, expression, tagName, field_options, options, values): field = record._fields[field_name] + # adds template compile options for rendering fields + for k, v in options.items(): + field_options.setdefault(k, v) + + # adds generic field options field_options['tagName'] = tagName field_options['expression'] = expression field_options['type'] = field_options.get('widget', field.type) diff --git a/odoo/addons/base/ir/ir_qweb/qweb.py b/odoo/addons/base/ir/ir_qweb/qweb.py index 6dac133b9b6..e12c89cd55a 100644 --- a/odoo/addons/base/ir/ir_qweb/qweb.py +++ b/odoo/addons/base/ir/ir_qweb/qweb.py @@ -5,7 +5,7 @@ import os.path import re import traceback -from collections import OrderedDict, Sized, Mapping, defaultdict +from collections import OrderedDict, Sized, Mapping from functools import reduce from itertools import tee, count from textwrap import dedent