From e829c1af55e491fad8e7a605e0e24ff722b3fe8f Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 23 Apr 2018 10:01:36 +0200 Subject: [PATCH] [FIX] website: apply cdn for background-image --- addons/website/models/ir_qweb.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/website/models/ir_qweb.py b/addons/website/models/ir_qweb.py index c2386d9466c..0f73bc469f5 100644 --- a/addons/website/models/ir_qweb.py +++ b/addons/website/models/ir_qweb.py @@ -1,11 +1,15 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import re from collections import OrderedDict from odoo import models from odoo.http import request +re_background_image = re.compile(r"(background-image\s*:\s*url\(\s*['\"]?\s*)([^)'\"]+)") + + class QWeb(models.AbstractModel): """ QWeb object for rendering stuff in the website context """ @@ -40,5 +44,8 @@ class QWeb(models.AbstractModel): if name and name in atts: atts = OrderedDict(atts) atts[name] = website.get_cdn_url(atts[name]) + if isinstance(atts.get('style'), str) and 'background-image' in atts['style']: + atts = OrderedDict(atts) + atts['style'] = re_background_image.sub(lambda m: '%s%s' % (m.group(1), website.get_cdn_url(m.group(2))), atts['style']) return atts