mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[15.0][MIG] web_widget_mpld3_chart
This commit is contained in:
committed by
Lois Rilo
parent
04c4e4fb46
commit
0f02e29462
1
web_widget_mpld3_chart/models/__init__.py
Normal file
1
web_widget_mpld3_chart/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import abstract_mpld3_parser
|
||||
33
web_widget_mpld3_chart/models/abstract_mpld3_parser.py
Normal file
33
web_widget_mpld3_chart/models/abstract_mpld3_parser.py
Normal 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)
|
||||
Reference in New Issue
Block a user