dataviz: display warning message when dataviz has no cached json (#38947)

This commit is contained in:
Frédéric Péters 2020-01-14 13:55:19 +01:00
parent 9fe9aaae62
commit 866615b2e0
5 changed files with 16 additions and 4 deletions

View File

@ -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:

View File

@ -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">

View File

@ -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>

View File

@ -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,

View File

@ -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')