[IMP] base, mail, portal: improves is_html_empty method

Before this commit there were few cases in which
is_html_empty method was not working as our expectation.
In cases such as "<p class=""><br/></p>", "<p id=""><br/></p>"
and many other cases.

In this commit we improves regex of is_html_empty method.
Mow from this commit all kind of attributes will be consider
in this method.

In this commit we also have added is_html_empty in mail template, portal
values and in report values also for rendering templates.

Task id: 2499504

X-original-commit: fd0a05f2955b9f7e9ae7233afebfd6240c9244dd
This commit is contained in:
dht-odoo
2021-06-07 05:21:40 +00:00
committed by Thibault Delavallée
parent 8c7e6d5dec
commit 57261b100f
5 changed files with 8 additions and 4 deletions
+2 -1
View File
@@ -14,7 +14,7 @@ from werkzeug import urls
from odoo import _, api, fields, models, tools
from odoo.exceptions import UserError
from odoo.tools import safe_eval
from odoo.tools import is_html_empty, safe_eval
_logger = logging.getLogger(__name__)
@@ -279,6 +279,7 @@ class MailRenderMixin(models.AbstractModel):
'format_duration': lambda value: tools.format_duration(value),
'user': self.env.user,
'ctx': self._context,
'is_html_empty': is_html_empty,
}
@api.model
+2
View File
@@ -4,6 +4,7 @@
from odoo import api, models, fields
from odoo.http import request
from odoo.addons.http_routing.models.ir_http import url_for
from odoo.tools import is_html_empty
class View(models.Model):
@@ -24,5 +25,6 @@ class View(models.Model):
self._context.copy(),
languages=[lang for lang in Lang.get_available() if lang[0] in portal_lang_code],
url_for=url_for,
is_html_empty=is_html_empty,
))
return qcontext
+2 -1
View File
@@ -6,7 +6,7 @@ from odoo import api, fields, models, tools, SUPERUSER_ID, _
from odoo.exceptions import UserError, AccessError
from odoo.tools.safe_eval import safe_eval, time
from odoo.tools.misc import find_in_path
from odoo.tools import config
from odoo.tools import config, is_html_empty
from odoo.sql_db import TestCursor
from odoo.http import request
from odoo.osv.expression import NEGATIVE_TERM_OPERATORS, FALSE_DOMAIN
@@ -886,6 +886,7 @@ class IrActionsReport(models.Model):
'doc_model': self_sudo.model,
'docs': docs,
})
data['is_html_empty'] = is_html_empty
return data
def _render(self, res_ids, data=None):
+1 -1
View File
@@ -329,7 +329,7 @@ class TestHtmlTools(BaseCase):
self.assertTrue(is_html_empty(content))
void_html_samples = ['<p><br></p>', '<p><br> </p>', '<p><br /></p >', '<p style="margin: 4px"></p>',
'<div style="margin: 4px"></div>']
'<div style="margin: 4px"></div>', '<p class="oe_testing"><br></p>']
for content in void_html_samples:
self.assertTrue(is_html_empty(content), 'Failed with %s' % content)
+1 -1
View File
@@ -279,7 +279,7 @@ def is_html_empty(html_content):
"""
if not html_content:
return True
tag_re = re.compile(r'\<\s*\/?(?:p|div|span|br|b|i)\s*(?:style=\".+\")?/?\s*\>')
tag_re = re.compile(r'\<\s*\/?(?:p|div|span|br|b|i)(?:(?=\s+\w*)[^/>]*|\s*)/?\s*\>')
return not bool(re.sub(tag_re, '', html_content).strip())