Projet

Général

Profil

0001-support-boolean-columns-fixes-16346.patch

Benjamin Dauvergne, 15 mai 2017 16:45

Télécharger (2,95 ko)

Voir les différences:

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(-)
README.rst
81 81
    * join: list of join names, indicate that some joins must be used when using
82 82
      this dimension,
83 83

  
84
    * type: indicate the type of the dimension, numerical, time-like,
85
      geographical, duration, etc..
84
    * type: indicate the type of the dimension, can be: integer, boolean or
85
      date.
86 86

  
87 87
    * value: SQL expression giving the value for the dimension,
88 88
      it can be different than the value used for filtering or grouping,
bijoe/engine.py
341 341
        sql = self.sql_query(filters=filters, drilldown=drilldown, measures=measures, **kwargs)
342 342
        self.engine.log.debug('SQL: %s', sql)
343 343
        cursor.execute(sql)
344

  
345
        def adapt_value(cell, value):
346
            if cell.type == 'boolean':
347
                if value is True:
348
                    value = 'Oui'
349
                elif value is False:
350
                    value = 'Non'
351
            return value
344 352
        for row in cursor.fetchall():
345 353
            yield [{
346 354
                'name': cell.name,
347 355
                'label': cell.label,
348 356
                'type': cell.type,
349
                'value': value,
357
                'value': adapt_value(cell, value),
350 358
            } for cell, value in zip(cells, row)]
351 359

  
352 360

  
bijoe/visualization/forms.py
19 19
from django.core.exceptions import ValidationError
20 20
from django.utils.translation import ugettext as _
21 21
from django.utils.safestring import mark_safe
22
from django.forms import ModelForm, TextInput
22
from django.forms import ModelForm, TextInput, NullBooleanField
23 23
from django.conf import settings
24 24

  
25 25
try:
......
173 173
            if dimension.type == 'date':
174 174
                self.base_fields[field_name] = DateRangeField(
175 175
                    label=dimension.label.capitalize(), required=False)
176
            elif dimension.type == 'boolean':
177
                self.base_fields[field_name] = NullBooleanField(
178
                    label=dimension.label.capitalize(), required=False)
176 179
            else:
177 180
                self.base_fields[field_name] = forms.MultipleChoiceField(
178 181
                    label=dimension.label.capitalize(),
179
-