dataviz: avoid crash if no table data (#48865)
This commit is contained in:
parent
18fdd8a8c4
commit
d8fbda7d42
|
@ -200,11 +200,14 @@ class ChartNgCell(CellBase):
|
|||
if e.response.status_code == 404:
|
||||
ctx['table'] = '<p>%s</p>' % _('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('<table>', '<table class="main">')
|
||||
if not chart.raw_series:
|
||||
ctx['table'] = '<p>%s</p>' % _('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('<table>', '<table class="main">')
|
||||
return ctx
|
||||
|
||||
def get_chart(self, width=None, height=None, raise_if_not_cached=False):
|
||||
|
|
|
@ -995,6 +995,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(statistics, nocache):
|
||||
all_stats_count = Statistic.objects.count()
|
||||
|
|
Loading…
Reference in New Issue