misc: add grouping of data by day (#57825)

This commit is contained in:
Benjamin Dauvergne 2021-10-13 15:25:12 +02:00
parent a722cf6153
commit 6a011b145a
4 changed files with 30 additions and 3 deletions

View File

@ -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'))]

View File

@ -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):

View File

@ -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(

View File

@ -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'],
]