Projet

Général

Profil

0001-dataviz-hide-time-range-field-from-filters-cell-if-t.patch

Valentin Deniaud, 05 avril 2022 16:09

Télécharger (2,65 ko)

Voir les différences:

Subject: [PATCH] dataviz: hide time range field from filters cell if templates
 are used (#63397)

 combo/apps/dataviz/forms.py |  7 ++++++-
 tests/test_dataviz.py       | 23 +++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
combo/apps/dataviz/forms.py
266 266
            self.fields[field].initial = getattr(first_cell, field)
267 267
        dynamic_fields = self.get_filter_fields(first_cell)
268 268
        dynamic_fields_values = {k: v for k, v in first_cell.filter_params.items()}
269
        self.update_time_range_choices(first_cell.statistic, exclude_template_choice=True)
269

  
270
        if first_cell.time_range == 'range-template':
271
            for field in self._meta.fields:
272
                self.fields.pop(field, None)
273
        else:
274
            self.update_time_range_choices(first_cell.statistic, exclude_template_choice=True)
270 275

  
271 276
        for cell in chart_cells[1:]:
272 277
            cell_filter_fields = self.get_filter_fields(cell)
tests/test_dataviz.py
2358 2358
    ]
2359 2359

  
2360 2360

  
2361
@with_httmock(new_api_mock)
2362
def test_chart_filters_cell_range_template(new_api_statistics, app, admin_user, nocache):
2363
    page = Page.objects.create(title='One', slug='index')
2364
    cell = ChartNgCell(page=page, order=1, placeholder='content')
2365
    cell.statistic = Statistic.objects.get(slug='one-serie')
2366
    cell.save()
2367
    ChartFiltersCell.objects.create(page=page, order=2, placeholder='content')
2368

  
2369
    app = login(app)
2370
    resp = app.get('/')
2371
    assert 'time_range' in resp.form.fields
2372
    assert 'time_range_start' in resp.form.fields
2373
    assert 'time_range_end' in resp.form.fields
2374

  
2375
    # if time range is set using templates, time range fields are hidden from filters
2376
    cell.time_range = 'range-template'
2377
    cell.save()
2378
    resp = app.get('/')
2379
    assert 'time_range' not in resp.form.fields
2380
    assert 'time_range_start' not in resp.form.fields
2381
    assert 'time_range_end' not in resp.form.fields
2382

  
2383

  
2361 2384
@with_httmock(new_api_mock)
2362 2385
def test_chart_filters_cell_with_subfilters(new_api_statistics, app, admin_user, nocache):
2363 2386
    page = Page.objects.create(title='One', slug='index')
2364
-