From b304782803ccca13797be1b44c8b5f788a728e02 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 13 Oct 2021 15:25:12 +0200 Subject: [PATCH] misc: add grouping of data by day (#57825) --- bijoe/engine.py | 2 -- bijoe/schemas.py | 2 ++ bijoe/visualization/forms.py | 2 +- tests/test_schema1.py | 27 +++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/bijoe/engine.py b/bijoe/engine.py index 0cbec26..96a8082 100644 --- a/bijoe/engine.py +++ b/bijoe/engine.py @@ -139,8 +139,6 @@ class EngineDimension: return hashlib.md5(force_bytes(key)).hexdigest() def members(self, filters=()): - assert self.type != 'date' - if self.type == 'bool': return [Member(id=True, label=_('Yes')), Member(id=False, label=_('No'))] diff --git a/bijoe/schemas.py b/bijoe/schemas.py index 12957ae..8911a45 100644 --- a/bijoe/schemas.py +++ b/bijoe/schemas.py @@ -202,6 +202,8 @@ class Dimension(Base): self.absent_label = _('N/A') else: raise NotImplementedError('not absent label for type %r' % self.type) + if self.type == 'date' and not self.value_label: + self.value_label = 'TO_CHAR(%s, \'DD/MM/YYYY\')' % self.value @property def dimensions(self): diff --git a/bijoe/visualization/forms.py b/bijoe/visualization/forms.py index 50aa845..05bde09 100644 --- a/bijoe/visualization/forms.py +++ b/bijoe/visualization/forms.py @@ -172,7 +172,7 @@ class CubeForm(forms.Form): dimension_choices = [('', '')] + [ (dimension.name, dimension.label) for dimension in cube.dimensions - if dimension.type not in ('datetime', 'date') + if dimension.type not in ('datetime',) ] # loop self.base_fields['loop'] = forms.ChoiceField( diff --git a/tests/test_schema1.py b/tests/test_schema1.py index 32c047c..de8837e 100644 --- a/tests/test_schema1.py +++ b/tests/test_schema1.py @@ -471,3 +471,30 @@ def test_select2_filter_widget(schema1, app, admin): resp = request_select2(app, response, 'filter__innersubcategory', term='é', page=2) assert len(resp['results']) == 1 assert resp['more'] is False + + +def test_date_dimension(schema1, app, admin): + login(app, admin) + response = app.get('/') + response = response.click('schema1') + response = response.click('Facts 1') + form = response.form + form.set('representation', 'table') + form.set('measure', 'simple_count') + form.set('drilldown_y', 'date') + form.set('filter__date_0', '2017-01-01') + form.set('filter__date_1', '2017-02-01') + response = form.submit('visualize') + assert get_table(response) == [ + ['Date', 'number of rows'], + ['01/01/2017', '1'], + ['02/01/2017', '1'], + ['03/01/2017', '1'], + ['04/01/2017', '1'], + ['05/01/2017', '1'], + ['06/01/2017', '1'], + ['07/01/2017', '1'], + ['08/01/2017', '1'], + ['09/01/2017', '1'], + ['10/01/2017', '1'] + ] -- 2.33.0