From d1a551a8c753ad4177a4cf0e07366643a239eb06 Mon Sep 17 00:00:00 2001 From: "laetitia.gangloff@acsone.eu" Date: Thu, 31 Jul 2014 09:52:26 +0200 Subject: [PATCH] add a css style expression on kpi --- mis_builder/models/mis_builder.py | 10 +++++++++- mis_builder/static/src/xml/mis_widget.xml | 12 +++++++----- mis_builder/views/mis_builder.xml | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/mis_builder/models/mis_builder.py b/mis_builder/models/mis_builder.py index 55ee1123..a5da6810 100644 --- a/mis_builder/models/mis_builder.py +++ b/mis_builder/models/mis_builder.py @@ -84,6 +84,7 @@ class mis_report_kpi(orm.Model): translate=True), 'expression': fields.char(required=True, string='Expression'), + 'css_style': fields.char(string='CSS style'), 'type': fields.selection([('num', _('Numeric')), ('pct', _('Percentage')), ('str', _('String'))], @@ -183,7 +184,7 @@ class mis_report_kpi(orm.Model): def _render_num(self, value, divider, dp, suffix, sign='-'): divider_label = _get_selection_label( self._columns['divider'].selection, divider) - fmt = '{:%s,.%df}%s%s' % (sign, dp, divider_label, suffix or '') + fmt = '{:%s,.%df}%s %s' % (sign, dp, divider_label, suffix or '') value = round(value / float(divider or 1), dp) or 0 return fmt.format(value) @@ -469,11 +470,18 @@ class mis_report_instance_period(orm.Model): kpi_val_comment = None localdict[kpi.name] = kpi_val + try: + kpi_style = None + if kpi.css_style: + kpi_style = safe_eval(kpi.css_style, localdict) + except: + kpi_style = None res[kpi.name] = { 'val': kpi_val, 'val_r': kpi_val_rendered, 'val_c': kpi_val_comment, + 'style': kpi_style, } return res diff --git a/mis_builder/static/src/xml/mis_widget.xml b/mis_builder/static/src/xml/mis_widget.xml index b998c297..19d4869a 100644 --- a/mis_builder/static/src/xml/mis_widget.xml +++ b/mis_builder/static/src/xml/mis_widget.xml @@ -24,11 +24,13 @@ - - - + + + + + diff --git a/mis_builder/views/mis_builder.xml b/mis_builder/views/mis_builder.xml index 0b343256..f75d587c 100644 --- a/mis_builder/views/mis_builder.xml +++ b/mis_builder/views/mis_builder.xml @@ -43,6 +43,7 @@ +