0001-dataviz-add-support-for-including-bijoe-graphs-12744.patch
combo/apps/dataviz/forms.py | ||
---|---|---|
21 | 21 |
from django.conf import settings |
22 | 22 |
from django.core.exceptions import ValidationError |
23 | 23 | |
24 |
from .models import BaseCubesChart |
|
24 |
from combo.utils import requests |
|
25 | ||
26 |
from .models import BaseCubesChart, ChartCell |
|
25 | 27 |
from .utils import get_cubes, get_cube, get_drilldown |
26 | 28 | |
27 | 29 | |
30 |
class ChartForm(forms.ModelForm): |
|
31 |
class Meta: |
|
32 |
model = ChartCell |
|
33 |
fields = ('title', 'url') |
|
34 | ||
35 |
def __init__(self, *args, **kwargs): |
|
36 |
super(ChartForm, self).__init__(*args, **kwargs) |
|
37 |
available_charts = [] |
|
38 |
for site_key, site_dict in settings.KNOWN_SERVICES.get('bijoe').items(): |
|
39 |
result = requests.get('/visualization/json/', |
|
40 |
remote_service=site_dict, without_user=True, |
|
41 |
headers={'accept': 'application/json'}).json() |
|
42 |
available_charts.extend([(x['path'], x['name']) for x in result]) |
|
43 |
available_charts.sort(key=lambda x: x[1]) |
|
44 |
self.fields['url'].widget = forms.Select(choices=available_charts) |
|
45 | ||
46 | ||
28 | 47 |
class CubesBarChartForm(forms.ModelForm): |
29 | 48 |
EMPTY = [(u'', _('None'))] |
30 | 49 |
combo/apps/dataviz/migrations/0005_chartcell.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
from __future__ import unicode_literals |
|
3 | ||
4 |
from django.db import migrations, models |
|
5 | ||
6 | ||
7 |
class Migration(migrations.Migration): |
|
8 | ||
9 |
dependencies = [ |
|
10 |
('data', '0019_create_parent_cells'), |
|
11 |
('auth', '0006_require_contenttypes_0002'), |
|
12 |
('dataviz', '0004_auto_20160108_1048'), |
|
13 |
] |
|
14 | ||
15 |
operations = [ |
|
16 |
migrations.CreateModel( |
|
17 |
name='ChartCell', |
|
18 |
fields=[ |
|
19 |
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), |
|
20 |
('placeholder', models.CharField(max_length=20)), |
|
21 |
('order', models.PositiveIntegerField()), |
|
22 |
('slug', models.SlugField(verbose_name='Slug', blank=True)), |
|
23 |
('public', models.BooleanField(default=True, verbose_name='Public')), |
|
24 |
('restricted_to_unlogged', models.BooleanField(default=False, verbose_name='Restrict to unlogged users')), |
|
25 |
('title', models.CharField(max_length=150, null=True, verbose_name='Title', blank=True)), |
|
26 |
('url', models.URLField(max_length=150, null=True, verbose_name='URL', blank=True)), |
|
27 |
('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)), |
|
28 |
('page', models.ForeignKey(to='data.Page')), |
|
29 |
], |
|
30 |
options={ |
|
31 |
'abstract': False, |
|
32 |
}, |
|
33 |
), |
|
34 |
] |
combo/apps/dataviz/models.py | ||
---|---|---|
61 | 61 |
} |
62 | 62 | |
63 | 63 | |
64 |
@register_cell_class |
|
65 |
class ChartCell(CellBase): |
|
66 |
template_name = 'combo/dataviz-chart.html' |
|
67 | ||
68 |
title = models.CharField(_('Title'), max_length=150, blank=True, null=True) |
|
69 |
url = models.URLField(_('URL'), max_length=150, blank=True, null=True) |
|
70 | ||
71 |
class Meta: |
|
72 |
verbose_name = _('Chart') |
|
73 | ||
74 |
@classmethod |
|
75 |
def is_enabled(self): |
|
76 |
return hasattr(settings, 'KNOWN_SERVICES') and settings.KNOWN_SERVICES.get('bijoe') |
|
77 | ||
78 |
def get_default_form_class(self): |
|
79 |
from .forms import ChartForm |
|
80 |
return ChartForm |
|
81 | ||
82 |
def get_additional_label(self): |
|
83 |
if self.title: |
|
84 |
return self.title |
|
85 |
return '' |
|
86 | ||
87 |
def get_cell_extra_context(self, context): |
|
88 |
context = super(ChartCell, self).get_cell_extra_context(context) |
|
89 |
context['title'] = self.title |
|
90 |
context['url'] = self.url |
|
91 |
return context |
|
92 | ||
64 | 93 |
class BaseCubesChart(CellBase): |
65 | 94 |
title = models.CharField(_('Title'), max_length=150, blank=True, null=True) |
66 | 95 |
url = models.URLField(_('URL'), max_length=150, blank=True, null=True) |
67 |
- |