From 5136f2024980f3ef49beebdee30a3faf3eabcad6 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Mon, 7 Dec 2020 12:35:56 +0100 Subject: [PATCH 3/3] dataviz: avoid crash if no table data (#48865) --- combo/apps/dataviz/models.py | 13 ++++++++----- tests/test_dataviz.py | 5 +++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py index afab1779..de87fbe1 100644 --- a/combo/apps/dataviz/models.py +++ b/combo/apps/dataviz/models.py @@ -200,11 +200,14 @@ class ChartNgCell(CellBase): if e.response.status_code == 404: ctx['table'] = '

%s

' % _('Visualization not found.') else: - ctx['table'] = chart.render_table( - transpose=bool(chart.axis_count == 2), - total=getattr(chart, 'compute_sum', True), - ) - ctx['table'] = ctx['table'].replace('', '
') + if not chart.raw_series: + ctx['table'] = '

%s

' % _('No data.') + else: + ctx['table'] = chart.render_table( + transpose=bool(chart.axis_count == 2), + total=getattr(chart, 'compute_sum', True), + ) + ctx['table'] = ctx['table'].replace('
', '
') return ctx def get_chart(self, width=None, height=None, raise_if_not_cached=False): diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index 25ee920b..0395a8c2 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -978,6 +978,11 @@ def test_table_cell_new_api(app, admin_user, new_api_statistics): assert '21' in resp.text assert resp.text.count('Total') == 2 + cell.statistic = Statistic.objects.get(slug='no-data') + cell.save() + resp = app.get('/') + assert resp.text.count('Total') == 0 + def test_dataviz_hourly_unavailable_statistic(freezer, statistics): all_stats_count = Statistic.objects.count() -- 2.20.1