dataviz: add support for including bijoe graphs (#12744)
This commit is contained in:
parent
539a17d1e0
commit
b83db4889c
|
@ -21,10 +21,29 @@ from django import forms
|
|||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from .models import BaseCubesChart
|
||||
from combo.utils import requests
|
||||
|
||||
from .models import BaseCubesChart, ChartCell
|
||||
from .utils import get_cubes, get_cube, get_drilldown
|
||||
|
||||
|
||||
class ChartForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = ChartCell
|
||||
fields = ('title', 'url')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ChartForm, self).__init__(*args, **kwargs)
|
||||
available_charts = []
|
||||
for site_key, site_dict in settings.KNOWN_SERVICES.get('bijoe').items():
|
||||
result = requests.get('/visualization/json/',
|
||||
remote_service=site_dict, without_user=True,
|
||||
headers={'accept': 'application/json'}).json()
|
||||
available_charts.extend([(x['path'], x['name']) for x in result])
|
||||
available_charts.sort(key=lambda x: x[1])
|
||||
self.fields['url'].widget = forms.Select(choices=available_charts)
|
||||
|
||||
|
||||
class CubesBarChartForm(forms.ModelForm):
|
||||
EMPTY = [(u'', _('None'))]
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('data', '0020_auto_20160928_1152'),
|
||||
('auth', '0006_require_contenttypes_0002'),
|
||||
('dataviz', '0005_auto_20160928_1152'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ChartCell',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('placeholder', models.CharField(max_length=20)),
|
||||
('order', models.PositiveIntegerField()),
|
||||
('slug', models.SlugField(verbose_name='Slug', blank=True)),
|
||||
('extra_css_class', models.CharField(max_length=100, verbose_name='Extra classes for CSS styling', blank=True)),
|
||||
('public', models.BooleanField(default=True, verbose_name='Public')),
|
||||
('restricted_to_unlogged', models.BooleanField(default=False, verbose_name='Restrict to unlogged users')),
|
||||
('title', models.CharField(max_length=150, null=True, verbose_name='Title', blank=True)),
|
||||
('url', models.URLField(max_length=150, null=True, verbose_name='URL', blank=True)),
|
||||
('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)),
|
||||
('page', models.ForeignKey(to='data.Page')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Chart',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -61,6 +61,35 @@ class Gauge(CellBase):
|
|||
}
|
||||
|
||||
|
||||
@register_cell_class
|
||||
class ChartCell(CellBase):
|
||||
template_name = 'combo/dataviz-chart.html'
|
||||
|
||||
title = models.CharField(_('Title'), max_length=150, blank=True, null=True)
|
||||
url = models.URLField(_('URL'), max_length=150, blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Chart')
|
||||
|
||||
@classmethod
|
||||
def is_enabled(self):
|
||||
return hasattr(settings, 'KNOWN_SERVICES') and settings.KNOWN_SERVICES.get('bijoe')
|
||||
|
||||
def get_default_form_class(self):
|
||||
from .forms import ChartForm
|
||||
return ChartForm
|
||||
|
||||
def get_additional_label(self):
|
||||
if self.title:
|
||||
return self.title
|
||||
return ''
|
||||
|
||||
def get_cell_extra_context(self, context):
|
||||
context = super(ChartCell, self).get_cell_extra_context(context)
|
||||
context['title'] = self.title
|
||||
context['url'] = self.url
|
||||
return context
|
||||
|
||||
class BaseCubesChart(CellBase):
|
||||
title = models.CharField(_('Title'), max_length=150, blank=True, null=True)
|
||||
url = models.URLField(_('URL'), max_length=150, blank=True, null=True)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{% if title %}<h2>{{title}}</h2>{% endif %}
|
||||
<iframe src="{{url}}" frameborder="0" width="100%" height="400px">
|
||||
</iframe>
|
Loading…
Reference in New Issue