[FIX] website: apply cdn for background-image

This commit is contained in:
Christophe Matthieu
2018-06-15 08:42:15 +02:00
committed by Jeremy Kersten
parent 9cd982bcc8
commit e829c1af55
+7
View File
@@ -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