Projet

Général

Profil

0001-schemas-fix-loop-handling-for-date-dimension-59691.patch

Benjamin Dauvergne, 15 décembre 2021 09:26

Télécharger (2,31 ko)

Voir les différences:

Subject: [PATCH] schemas: fix loop handling for date dimension (#59691)

When date dimension is used with a loop, the filter is a list of date
instead of date range dictionnary.
 bijoe/schemas.py      |  9 +++++++--
 tests/test_schema1.py | 15 +++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
bijoe/schemas.py
288 288
    def build_filter(self, filter_values):
289 289
        value = self.filter_value or self.value
290 290

  
291
        if self.type == 'date':
292
            assert isinstance(filter_values, dict) and set(filter_values.keys()) == {'start', 'end'}
291
        if (
292
            self.type == 'date'
293
            and isinstance(filter_values, dict)
294
            and set(filter_values.keys()) == {'start', 'end'}
295
        ):
293 296
            filters = []
294 297
            values = []
295 298

  
......
326 329
                        filter_value = int(filter_value)
327 330
                    elif self.type == 'bool':
328 331
                        filter_value = bool(filter_value)
332
                    elif self.type == 'date':
333
                        filter_value = filter_value.isoformat()
329 334
                    else:
330 335
                        raise NotImplementedError
331 336
                except (ValueError, TypeError):
tests/test_schema1.py
498 498
        ['09/01/2017', '1'],
499 499
        ['10/01/2017', '1'],
500 500
    ]
501

  
502

  
503
def test_date_dimension_loop(schema1, app, admin):
504
    login(app, admin)
505
    response = app.get('/')
506
    response = response.click('schema1')
507
    response = response.click('Facts 1')
508
    form = response.form
509
    form.set('representation', 'table')
510
    form.set('measure', 'simple_count')
511
    form.set('loop', 'date')
512
    form.set('filter__date_0', '2017-01-01')
513
    form.set('filter__date_1', '2017-02-01')
514
    response = form.submit('visualize')
515
    assert get_table(response) == [['number of rows', '1']] * 10
501
-