Projet

Général

Profil

0001-dataviz-handle-empty-percentage-value-38847.patch

Valentin Deniaud, 08 janvier 2020 16:03

Télécharger (1,74 ko)

Voir les différences:

Subject: [PATCH] dataviz: handle empty percentage value (#38847)

 combo/apps/dataviz/models.py | 2 +-
 tests/test_dataviz.py        | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
combo/apps/dataviz/models.py
290 290
                return force_text(value)
291 291
            chart.config.value_formatter = format_duration
292 292
        elif response.get('measure') == 'percent':
293
            percent_formatter = lambda x: '{:.1f}%'.format(x)
293
            percent_formatter = lambda x: '0%' if x is None else '{:.1f}%'.format(x)
294 294
            chart.config.value_formatter = percent_formatter
295 295

  
296 296
        return chart
tests/test_dataviz.py
220 220
    if url.path == '/visualization/10/json/':
221 221
        response = {
222 222
            'format': '1',
223
            'data': [10, 20, 30, 40],
223
            'data': [10, 20, 30, 40, None],
224 224
            'axis': {
225 225
                'y_labels': ['web', 'mail', 'email', 'fax']
226 226
            },
......
422 422
            resp = app.get('/api/dataviz/graph/1/')  # get data in cache
423 423
            resp = app.get('/')
424 424
            assert '<td>10.0%</td>' in resp.text
425
            assert '<td>0%</td>' in resp.text
425 426

  
426 427
            cell.chart_type = 'bar'
427 428
            cell.save()
428
-