[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

@@ -8,7 +8,7 @@
"version": "12.0.1.0.0",
"license": "AGPL-3",
"author": "Creu Blanca,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine ",
"website": "https://github.com/OCA/reporting-engine",
"depends": ["web_widget_bokeh_chart", "kpi_dashboard"],
"data": ["views/webclient_templates.xml"],
"qweb": ["static/src/xml/dashboard.xml"],

View File

@@ -13,13 +13,12 @@ result = {"bokeh": "%s%s" % (div, script)}
</field>
</record>
<function model="kpi.kpi" name="compute"
eval="[[ref('widget_bokeh')]]"/>
<function model="kpi.kpi" name="compute" eval="[[ref('widget_bokeh')]]" />
<record id="dashboard_widget_bokeh" model="kpi.dashboard.item">
<field name="name">Bokeh</field>
<field name="dashboard_id" ref="kpi_dashboard.demo_dashboard"/>
<field name="kpi_id" ref="widget_bokeh"/>
<field name="dashboard_id" ref="kpi_dashboard.demo_dashboard" />
<field name="kpi_id" ref="widget_bokeh" />
<field name="column">2</field>
<field name="row">10</field>
<field name="size_y">4</field>

View File

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

View File

@@ -1,20 +1,19 @@
odoo.define('kpi_dashboard.BokehWidget', function (require) {
odoo.define("kpi_dashboard.BokehWidget", function (require) {
"use strict";
var AbstractWidget = require('kpi_dashboard.AbstractWidget');
var registry = require('kpi_dashboard.widget_registry');
var AbstractWidget = require("kpi_dashboard.AbstractWidget");
var registry = require("kpi_dashboard.widget_registry");
var BokehWidget = AbstractWidget.extend({
template: 'kpi_dashboard.bokeh',
template: "kpi_dashboard.bokeh",
fillWidget: function (values) {
var val = values.value.bokeh;
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);
},
});
registry.add('bokeh', BokehWidget);
registry.add("bokeh", BokehWidget);
return BokehWidget;
});

View File

@@ -2,7 +2,7 @@
<template>
<t t-name="kpi_dashboard.bokeh" t-extend="kpi_dashboard.base_widget">
<t t-jquery="h1" t-operation="after">
<div data-bind="value"/>
<div data-bind="value" />
</t>
</t>

View File

@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="assets_backend"
name="Backend Assets (used in backend interface)"
inherit_id="web.assets_backend">
<template
id="assets_backend"
name="Backend Assets (used in backend interface)"
inherit_id="web.assets_backend"
>
<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>
</template>
</odoo>