[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

@ -8,18 +8,12 @@
"category": "Tools",
"website": "https://github.com/OCA/server-tools",
"author": "Grupo ESOC Ingeniería de Servicios, "
"Tecnativa, "
"Onestein, "
"Odoo Community Association (OCA)",
"Tecnativa, "
"Onestein, "
"Odoo Community Association (OCA)",
"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
@ -63,7 +65,7 @@ class IrFieldsConverter(models.AbstractModel):
# Truncate text
suffix = suffix or max_chars and len(text) > max_chars
if max_chars:
text = text[:max_chars - (len(ellipsis) if suffix else 0)].strip()
text = text[: max_chars - (len(ellipsis) if suffix else 0)].strip()
# Append ellipsis if needed
if suffix:

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):