Skip to content

Commit

Permalink
Merge c3b23d5 into 3e36852
Browse files Browse the repository at this point in the history
  • Loading branch information
hugho-ad committed Jul 16, 2019
2 parents 3e36852 + c3b23d5 commit 0ae5f81
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions website_lazy_load_image/models/ir_ui_view.py
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
from lxml import etree
from lxml.etree import HTML, XMLSyntaxError, fromstring, HTMLParser, tostring


class IrUiView(models.Model):
Expand All @@ -22,7 +22,11 @@ def render_template(self, template, values=None, engine='ir.qweb'):
website_id = self.env.context.get('website_id')
if website_id and not \
self.env['website'].browse(website_id).is_publisher():
html = etree.HTML(res)
try:
html = fromstring(res)
except XMLSyntaxError:
myparser = HTMLParser(encoding="utf-8")
html = HTML(res, parser=myparser)
imgs = html.xpath(
'//main//img[@src][not(hasclass("lazyload-disable"))]'
) + html.xpath(
Expand All @@ -32,5 +36,5 @@ def render_template(self, template, values=None, engine='ir.qweb'):
src = img.attrib['src']
img.attrib['src'] = self.LAZYLOAD_DEFAULT_SRC
img.attrib['data-src'] = src
res = etree.tostring(html, method='html')
res = tostring(html, method='html', encoding='UTF-8')
return res

0 comments on commit 0ae5f81

Please sign in to comment.