[IMP] kpi_dasboard_bokeh: black, isort, prettier

This commit is contained in:
Enric Tobella
2021-04-28 10:14:15 +02:00
parent 21bc6282c1
commit a5e9c7cc35
8 changed files with 59 additions and 43 deletions

View File

@@ -13,8 +13,7 @@ result = {"bokeh": "%s%s" % (div, script)}
</field> </field>
</record> </record>
<function model="kpi.kpi" name="compute" <function model="kpi.kpi" name="compute" eval="[[ref('widget_bokeh')]]" />
eval="[[ref('widget_bokeh')]]"/>
<record id="dashboard_widget_bokeh" model="kpi.dashboard.item"> <record id="dashboard_widget_bokeh" model="kpi.dashboard.item">
<field name="name">Bokeh</field> <field name="name">Bokeh</field>

View File

@@ -1,14 +1,15 @@
# Copyright 2020 Creu Blanca # Copyright 2020 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
import logging import logging
from odoo import fields, models
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try: try:
from bokeh.embed import components
from bokeh.plotting import figure from bokeh.plotting import figure
from bokeh.themes import Theme from bokeh.themes import Theme
from bokeh.embed import components
except ImportError as e: except ImportError as e:
_logger.error(e) _logger.error(e)
@@ -20,7 +21,8 @@ class KpiKpi(models.Model):
widget = fields.Selection(selection_add=[("bokeh", "Bokeh")]) widget = fields.Selection(selection_add=[("bokeh", "Bokeh")])
def _get_bokeh_theme(self): def _get_bokeh_theme(self):
return Theme(json={ return Theme(
json={
"attrs": { "attrs": {
"Figure": { "Figure": {
"background_fill_alpha": 0, "background_fill_alpha": 0,
@@ -36,15 +38,19 @@ class KpiKpi(models.Model):
"background_fill_alpha": 0, "background_fill_alpha": 0,
}, },
} }
}) }
)
def _get_code_input_dict(self): def _get_code_input_dict(self):
res = super()._get_code_input_dict() res = super()._get_code_input_dict()
if self.widget == 'bokeh': if self.widget == "bokeh":
res.update({ res.update(
'figure': figure, {
'components': components, "figure": figure,
'simple_components': lambda r: components( "components": components,
r, theme=self._get_bokeh_theme()) "simple_components": lambda r: components(
}) r, theme=self._get_bokeh_theme()
),
}
)
return res return res

View File

@@ -1,20 +1,19 @@
odoo.define('kpi_dashboard.BokehWidget', function (require) { odoo.define("kpi_dashboard.BokehWidget", function (require) {
"use strict"; "use strict";
var AbstractWidget = require('kpi_dashboard.AbstractWidget'); var AbstractWidget = require("kpi_dashboard.AbstractWidget");
var registry = require('kpi_dashboard.widget_registry'); var registry = require("kpi_dashboard.widget_registry");
var BokehWidget = AbstractWidget.extend({ var BokehWidget = AbstractWidget.extend({
template: 'kpi_dashboard.bokeh', template: "kpi_dashboard.bokeh",
fillWidget: function (values) { fillWidget: function (values) {
var val = values.value.bokeh; var val = values.value.bokeh;
var widget = this.$el.find('[data-bind="value"]'); var widget = this.$el.find('[data-bind="value"]');
widget.css('height', this.widget_size_y - 90); widget.css("height", this.widget_size_y - 90);
widget.html(val); widget.html(val);
}, },
}); });
registry.add('bokeh', BokehWidget); registry.add("bokeh", BokehWidget);
return BokehWidget; return BokehWidget;
}); });

View File

@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<template id="assets_backend" <template
id="assets_backend"
name="Backend Assets (used in backend interface)" name="Backend Assets (used in backend interface)"
inherit_id="web.assets_backend"> inherit_id="web.assets_backend"
>
<xpath expr="." position="inside"> <xpath expr="." position="inside">
<script type="text/javascript" src="/kpi_dashboard_bokeh/static/src/js/bokeh_widget.js"/> <script
type="text/javascript"
src="/kpi_dashboard_bokeh/static/src/js/bokeh_widget.js"
/>
</xpath> </xpath>
</template> </template>
</odoo> </odoo>

View File

@@ -0,0 +1 @@
../../../../kpi_dashboard_bokeh

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)