[IMP] html_text: black, isort, prettier

pull/2590/head
Víctor Martínez 2021-02-19 10:49:09 +01:00 committed by dsolanki
parent 18481b71ac
commit f5cab2b92f
3 changed files with 21 additions and 23 deletions

View File

@ -14,12 +14,6 @@
"license": "AGPL-3",
"application": False,
"installable": True,
"external_dependencies": {
"python": [
"lxml",
],
},
"depends": [
"base",
],
"external_dependencies": {"python": ["lxml",],},
"depends": ["base",],
}

View File

@ -3,7 +3,9 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
from lxml import etree, html
from odoo import api, models
_logger = logging.getLogger(__name__)
@ -13,8 +15,9 @@ class IrFieldsConverter(models.AbstractModel):
_inherit = "ir.fields.converter"
@api.model
def text_from_html(self, html_content, max_words=None, max_chars=None,
ellipsis=u"", fail=False):
def text_from_html(
self, html_content, max_words=None, max_chars=None, ellipsis=u"", fail=False
):
"""Extract text from an HTML field in a generator.
:param str html_content:
@ -45,8 +48,7 @@ class IrFieldsConverter(models.AbstractModel):
if fail:
raise
else:
_logger.exception("Failure parsing this HTML:\n%s",
html_content)
_logger.exception("Failure parsing this HTML:\n%s", html_content)
return ""
# Get words

View File

@ -1,8 +1,8 @@
# Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tools import mute_logger
from odoo.tests.common import TransactionCase
from odoo.tools import mute_logger
class ExtractorCase(TransactionCase):
@ -27,16 +27,18 @@ class ExtractorCase(TransactionCase):
self.assertEqual(
self.text_from_html(html),
u"I'm a title I'm a paragraph ¡Pues yo soy español!")
u"I'm a title I'm a paragraph ¡Pues yo soy español!",
)
self.assertEqual(
self.text_from_html(html, 8),
u"I'm a title I'm a paragraph ¡Pues yo…")
self.text_from_html(html, 8), u"I'm a title I'm a paragraph ¡Pues yo…"
)
self.assertEqual(
self.text_from_html(html, 8, 31),
u"I'm a title I'm a paragraph ¡P…")
self.text_from_html(html, 8, 31), u"I'm a title I'm a paragraph ¡P…"
)
self.assertEqual(
self.text_from_html(html, 7, ellipsis=""),
u"I'm a title I'm a paragraph ¡Pues")
u"I'm a title I'm a paragraph ¡Pues",
)
@mute_logger("odoo.addons.html_text.models.ir_fields_converter")
def test_empty_html(self):