Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
30
web_widget_mpld3_chart/models/abstract_mpld3_parser.py
Executable file
30
web_widget_mpld3_chart/models/abstract_mpld3_parser.py
Executable file
@@ -0,0 +1,30 @@
|
||||
# Copyright 2022 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
import mpld3
|
||||
from bs4 import BeautifulSoup
|
||||
except (OSError, ImportError) as err:
|
||||
_logger.debug(err)
|
||||
|
||||
|
||||
class AbstractMpld3Parser(models.AbstractModel):
|
||||
_name = "abstract.mpld3.parser"
|
||||
_description = "Utility to parse ploot figure to json data for widget Mpld3"
|
||||
|
||||
@api.model
|
||||
def convert_figure_to_json(self, figure):
|
||||
html_string = mpld3.fig_to_html(figure, no_extras=True, include_libraries=False)
|
||||
soup = BeautifulSoup(html_string, "lxml")
|
||||
json_data = {
|
||||
"div": str(soup.div),
|
||||
"script": soup.script.decode_contents(),
|
||||
}
|
||||
return json_data
|
||||
Reference in New Issue
Block a user