From b979c7104d4cd8741339279fab703ad2b6a2139c Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sun, 14 May 2017 15:33:23 +0200 Subject: [PATCH] support boolean columns (fixes #16346) --- README.rst | 4 ++-- bijoe/engine.py | 10 +++++++++- bijoe/visualization/forms.py | 5 ++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 020295c..ee4bc23 100644 --- a/README.rst +++ b/README.rst @@ -81,8 +81,8 @@ The JSON model files must conform to this schema: * join: list of join names, indicate that some joins must be used when using this dimension, - * type: indicate the type of the dimension, numerical, time-like, - geographical, duration, etc.. + * type: indicate the type of the dimension, can be: integer, boolean or + date. * value: SQL expression giving the value for the dimension, it can be different than the value used for filtering or grouping, diff --git a/bijoe/engine.py b/bijoe/engine.py index be8645d..b3c4e35 100644 --- a/bijoe/engine.py +++ b/bijoe/engine.py @@ -341,12 +341,20 @@ class EngineCube(object): sql = self.sql_query(filters=filters, drilldown=drilldown, measures=measures, **kwargs) self.engine.log.debug('SQL: %s', sql) cursor.execute(sql) + + def adapt_value(cell, value): + if cell.type == 'boolean': + if value is True: + value = 'Oui' + elif value is False: + value = 'Non' + return value for row in cursor.fetchall(): yield [{ 'name': cell.name, 'label': cell.label, 'type': cell.type, - 'value': value, + 'value': adapt_value(cell, value), } for cell, value in zip(cells, row)] diff --git a/bijoe/visualization/forms.py b/bijoe/visualization/forms.py index dd420cb..d26ac06 100644 --- a/bijoe/visualization/forms.py +++ b/bijoe/visualization/forms.py @@ -19,7 +19,7 @@ from django import forms from django.core.exceptions import ValidationError from django.utils.translation import ugettext as _ from django.utils.safestring import mark_safe -from django.forms import ModelForm, TextInput +from django.forms import ModelForm, TextInput, NullBooleanField from django.conf import settings try: @@ -173,6 +173,9 @@ class CubeForm(forms.Form): if dimension.type == 'date': self.base_fields[field_name] = DateRangeField( label=dimension.label.capitalize(), required=False) + elif dimension.type == 'boolean': + self.base_fields[field_name] = NullBooleanField( + label=dimension.label.capitalize(), required=False) else: self.base_fields[field_name] = forms.MultipleChoiceField( label=dimension.label.capitalize(), -- 2.1.4