diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py index 4224c937..73f046cd 100644 --- a/combo/apps/dataviz/models.py +++ b/combo/apps/dataviz/models.py @@ -161,7 +161,7 @@ class ChartNgCell(CellBase): def get_cell_extra_context(self, context): ctx = super(ChartNgCell, self).get_cell_extra_context(context) - if self.chart_type == 'table': + if self.chart_type == 'table' and self.cached_json: try: chart = self.get_chart(raise_if_not_cached=not(context.get('synchronous'))) except UnsupportedDataSet: diff --git a/combo/apps/dataviz/templates/combo/chartngcell.html b/combo/apps/dataviz/templates/combo/chartngcell.html index 0986ab09..7a7bf34c 100644 --- a/combo/apps/dataviz/templates/combo/chartngcell.html +++ b/combo/apps/dataviz/templates/combo/chartngcell.html @@ -1,6 +1,8 @@ {% load i18n %} {% if cell.title %}

{{cell.title}}

{% endif %} -{% if cell.chart_type == "table" %} +{% if not cell.cached_json %} +
{% trans "Unavailable data." %}
+{% elif cell.chart_type == "table" %} {{table|safe}} {% else %}
diff --git a/combo/apps/dataviz/templates/combo/chartngcell_form.html b/combo/apps/dataviz/templates/combo/chartngcell_form.html index aafc5394..b0717869 100644 --- a/combo/apps/dataviz/templates/combo/chartngcell_form.html +++ b/combo/apps/dataviz/templates/combo/chartngcell_form.html @@ -1,6 +1,6 @@
{{ form.as_p }} -{% if cell.chart_type != "table" and cell.is_relevant %} +{% if cell.cached_json and cell.chart_type != "table" and cell.is_relevant %}
diff --git a/combo/apps/dataviz/views.py b/combo/apps/dataviz/views.py index 54d28314..9810d6ee 100644 --- a/combo/apps/dataviz/views.py +++ b/combo/apps/dataviz/views.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from django.core.exceptions import PermissionDenied -from django.http import HttpResponse +from django.http import HttpResponse, Http404 from django.utils.translation import ugettext_lazy as _ from combo.utils import get_templated_url, requests @@ -34,6 +34,8 @@ def dataviz_graph(request, *args, **kwargs): raise PermissionDenied() if not cell.is_visible(request.user): raise PermissionDenied() + if not cell.cached_json: + raise Http404('misconfigured cell') try: chart = cell.get_chart( width=int(request.GET.get('width', 0)) or None, diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index 648516ca..fa4c5abf 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -428,6 +428,14 @@ def test_chartng_cell_view(app, normal_user): resp = app.get('/api/dataviz/graph/1/?width=400', status=200) assert '>10.0%<' in resp.text + # cell with missing cached_json (probably after import and missing + # bijoe visualisation) + cell.chart_type = 'table' + cell.save() + ChartNgCell.objects.filter(id=cell.id).update(cached_json={}) + resp = app.get('/') + assert 'warningnotice' in resp.text + def test_chartng_cell_manager(app, admin_user): page = Page(title='One', slug='index')