combo/combo/apps/dataviz/views.py

41 lines
1.6 KiB
Python

# combo - content management system
# Copyright (C) 2015-2019 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from combo.utils import get_templated_url, requests
from .models import Gauge, ChartNgCell
def ajax_gauge_count(request, *args, **kwargs):
gauge = Gauge.objects.get(id=kwargs['cell'])
response = requests.get(get_templated_url(gauge.data_source))
return HttpResponse(response.content, content_type='text/json')
def dataviz_graph(request, *args, **kwargs):
cell = ChartNgCell.objects.get(id=kwargs.get('cell'))
if not cell.page.is_visible(request.user):
raise PermissionDenied()
if not cell.is_visible(request.user):
raise PermissionDenied()
chart = cell.get_chart(
width=int(request.GET.get('width', 0)) or None,
height=int(request.GET.get('height', 0)) or int(cell.height)
)
return HttpResponse(chart.render(), content_type='image/svg+xml')