Projet

Général

Profil

0003-dataviz-avoid-crash-if-no-table-data-48865.patch

Valentin Deniaud, 07 décembre 2020 16:40

Télécharger (2,1 ko)

Voir les différences:

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(-)
combo/apps/dataviz/models.py
200 200
                if e.response.status_code == 404:
201 201
                    ctx['table'] = '<p>%s</p>' % _('Visualization not found.')
202 202
            else:
203
                ctx['table'] = chart.render_table(
204
                    transpose=bool(chart.axis_count == 2),
205
                    total=getattr(chart, 'compute_sum', True),
206
                )
207
                ctx['table'] = ctx['table'].replace('<table>', '<table class="main">')
203
                if not chart.raw_series:
204
                    ctx['table'] = '<p>%s</p>' % _('No data.')
205
                else:
206
                    ctx['table'] = chart.render_table(
207
                        transpose=bool(chart.axis_count == 2),
208
                        total=getattr(chart, 'compute_sum', True),
209
                    )
210
                    ctx['table'] = ctx['table'].replace('<table>', '<table class="main">')
208 211
        return ctx
209 212

  
210 213
    def get_chart(self, width=None, height=None, raise_if_not_cached=False):
tests/test_dataviz.py
978 978
    assert '21' in resp.text
979 979
    assert resp.text.count('Total') == 2
980 980

  
981
    cell.statistic = Statistic.objects.get(slug='no-data')
982
    cell.save()
983
    resp = app.get('/')
984
    assert resp.text.count('Total') == 0
985

  
981 986

  
982 987
def test_dataviz_hourly_unavailable_statistic(freezer, statistics):
983 988
    all_stats_count = Statistic.objects.count()
984
-