[15.0][MIG] web_widget_mpld3_chart

This commit is contained in:
Christopher Ormaza
2022-01-07 15:27:54 -05:00
committed by Lois Rilo
parent 04c4e4fb46
commit 0f02e29462
17 changed files with 20775 additions and 1602 deletions

View File

@@ -0,0 +1 @@
from . import abstract_mpld3_parser

View File

@@ -0,0 +1,33 @@
# Copyright 2022 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import json
import logging
from odoo import api, models
_logger = logging.getLogger(__name__)
try:
import mpld3
from bs4 import BeautifulSoup
except (ImportError, IOError) 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 = {
"style": soup.style.decode(),
"div": soup.div.get("id"),
"script": soup.script.decode_contents(),
}
return json.dumps(json_data)