Projet

Général

Profil

0001-dataviz-display-warning-message-when-dataviz-has-no-.patch

Frédéric Péters, 14 janvier 2020 14:46

Télécharger (3,33 ko)

Voir les différences:

Subject: [PATCH] dataviz: display warning message when dataviz has no cached
 json (#38947)

 combo/apps/dataviz/models.py                        | 2 +-
 combo/apps/dataviz/templates/combo/chartngcell.html | 4 +++-
 combo/apps/dataviz/views.py                         | 4 +++-
 tests/test_dataviz.py                               | 8 ++++++++
 4 files changed, 15 insertions(+), 3 deletions(-)
combo/apps/dataviz/models.py
161 161

  
162 162
    def get_cell_extra_context(self, context):
163 163
        ctx = super(ChartNgCell, self).get_cell_extra_context(context)
164
        if self.chart_type == 'table':
164
        if self.chart_type == 'table' and self.cached_json:
165 165
            try:
166 166
                chart = self.get_chart(raise_if_not_cached=not(context.get('synchronous')))
167 167
            except UnsupportedDataSet:
combo/apps/dataviz/templates/combo/chartngcell.html
1 1
{% load i18n %}
2 2
{% if cell.title %}<h2>{{cell.title}}</h2>{% endif %}
3
{% if cell.chart_type == "table" %}
3
{% if not cell.cached_json %}
4
<div class="warningnotice">{% trans "Unavailable data." %}</div>
5
{% elif cell.chart_type == "table" %}
4 6
{{table|safe}}
5 7
{% else %}
6 8
<div style="min-height: {{cell.height}}px">
combo/apps/dataviz/views.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
from django.core.exceptions import PermissionDenied
18
from django.http import HttpResponse
18
from django.http import HttpResponse, Http404
19 19
from django.utils.translation import ugettext_lazy as _
20 20

  
21 21
from combo.utils import get_templated_url, requests
......
34 34
        raise PermissionDenied()
35 35
    if not cell.is_visible(request.user):
36 36
        raise PermissionDenied()
37
    if not cell.cached_json:
38
        raise Http404()
37 39
    try:
38 40
        chart = cell.get_chart(
39 41
                width=int(request.GET.get('width', 0)) or None,
tests/test_dataviz.py
428 428
            resp = app.get('/api/dataviz/graph/1/?width=400', status=200)
429 429
            assert '>10.0%<' in resp.text
430 430

  
431
            # cell with missing cached_json (probably after import and missing
432
            # bijoe visualisation)
433
            cell.chart_type = 'table'
434
            cell.save()
435
            ChartNgCell.objects.filter(id=cell.id).update(cached_json={})
436
            resp = app.get('/')
437
            assert 'warningnotice' in resp.text
438

  
431 439

  
432 440
def test_chartng_cell_manager(app, admin_user):
433 441
    page = Page(title='One', slug='index')
434
-