summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2020-01-14 12:55:19 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2020-01-15 13:56:53 (GMT)
commit866615b2e094e7f5834e468c8d94b5fc1204e9c7 (patch)
tree21a80a63a4ed5372a239c43657d138d63ae019fb
parent9fe9aaae62246d54307889c71891128d278f5d8a (diff)
downloadcombo-866615b2e094e7f5834e468c8d94b5fc1204e9c7.zip
combo-866615b2e094e7f5834e468c8d94b5fc1204e9c7.tar.gz
combo-866615b2e094e7f5834e468c8d94b5fc1204e9c7.tar.bz2
dataviz: display warning message when dataviz has no cached json (#38947)
-rw-r--r--combo/apps/dataviz/models.py2
-rw-r--r--combo/apps/dataviz/templates/combo/chartngcell.html4
-rw-r--r--combo/apps/dataviz/templates/combo/chartngcell_form.html2
-rw-r--r--combo/apps/dataviz/views.py4
-rw-r--r--tests/test_dataviz.py8
5 files changed, 16 insertions, 4 deletions
diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py
index 4224c93..73f046c 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 0986ab0..7a7bf34 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 %}<h2>{{cell.title}}</h2>{% endif %}
-{% if cell.chart_type == "table" %}
+{% if not cell.cached_json %}
+<div class="warningnotice">{% trans "Unavailable data." %}</div>
+{% elif cell.chart_type == "table" %}
{{table|safe}}
{% else %}
<div style="min-height: {{cell.height}}px">
diff --git a/combo/apps/dataviz/templates/combo/chartngcell_form.html b/combo/apps/dataviz/templates/combo/chartngcell_form.html
index aafc539..b071786 100644
--- a/combo/apps/dataviz/templates/combo/chartngcell_form.html
+++ b/combo/apps/dataviz/templates/combo/chartngcell_form.html
@@ -1,6 +1,6 @@
<div style="position: relative">
{{ 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 %}
<div style="position: absolute; right: 0; top: 0; width: 300px; height: 150px">
<embed type="image/svg+xml" src="{% url 'combo-dataviz-graph' cell=cell.id %}?width=300&height=150"/>
</div>
diff --git a/combo/apps/dataviz/views.py b/combo/apps/dataviz/views.py
index 54d2831..9810d6e 100644
--- a/combo/apps/dataviz/views.py
+++ b/combo/apps/dataviz/views.py
@@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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 648516c..fa4c5ab 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')