0001-views-grey-out-unavailable-visualizations-27412.patch
bijoe/templates/bijoe/homepage.html | ||
---|---|---|
9 | 9 |
{% block content %} |
10 | 10 |
{% if visualizations %} |
11 | 11 |
<h2>{% trans "Visualizations" %}</h2> |
12 |
<ul class="objects-list single-links bijoe-visualizations"> |
|
13 |
{% for visualization in visualizations %} |
|
14 |
{% url 'visualization' pk=visualization.pk as visualization_url %} |
|
15 |
<li><a href="{{ visualization_url }}">{{ visualization.name }}</a></li> |
|
16 |
{% endfor %} |
|
17 |
</ul> |
|
12 |
{% include "bijoe/visualizations_list.html" %} |
|
18 | 13 |
{% endif %} |
19 | 14 |
{% if warehouses %} |
20 | 15 |
<h2>{% trans "Data sources" %}</h2> |
bijoe/templates/bijoe/visualizations.html | ||
---|---|---|
11 | 11 |
{% endblock %} |
12 | 12 | |
13 | 13 |
{% block content %} |
14 |
<ul class="objects-list single-links bijoe-visualizations"> |
|
15 |
{% for visualization in object_list %} |
|
16 |
<li><a href="{% url "visualization" pk=visualization.pk %}">{{ visualization.name }}</a></li> |
|
17 |
{% endfor %} |
|
18 |
</ul> |
|
14 |
{% include "bijoe/visualizations_list.html" %} |
|
19 | 15 |
{% endblock %} |
bijoe/templates/bijoe/visualizations_list.html | ||
---|---|---|
1 |
{% load i18n %} |
|
2 | ||
3 |
<ul class="objects-list single-links bijoe-visualizations"> |
|
4 |
{% for visualization, exists in visualizations.items %} |
|
5 |
{% url 'visualization' pk=visualization.pk as visualization_url %} |
|
6 |
<li><a {% if exists %}href="{{ visualization_url }}"{% else %}class="disabled" title="{% trans "Form data not found" %}"{% endif %}> |
|
7 |
{{ visualization.name }} |
|
8 |
</a></li> |
|
9 |
{% endfor %} |
|
10 |
</ul> |
bijoe/views.py | ||
---|---|---|
35 | 35 |
from .utils import get_warehouses |
36 | 36 |
from .engine import Engine |
37 | 37 |
from .visualization.models import Visualization |
38 |
from .visualization.utils import Visualization as VisuUtil |
|
38 | 39 | |
39 | 40 | |
40 | 41 |
class AuthorizationMixin(object): |
... | ... | |
58 | 59 | |
59 | 60 |
def get_context_data(self, **kwargs): |
60 | 61 |
ctx = super(HomepageView, self).get_context_data(**kwargs) |
61 |
ctx['visualizations'] = Visualization.objects.all() |
|
62 |
visualizations = Visualization.objects.all() |
|
63 |
ctx['visualizations'] = {v: VisuUtil.exists(v, request=self.request) |
|
64 |
for v in visualizations} |
|
62 | 65 |
ctx['warehouses'] = sorted((Engine(w) for w in get_warehouses(self.request)), |
63 | 66 |
key=lambda w: w.label) |
64 | 67 |
return ctx |
bijoe/visualization/utils.py | ||
---|---|---|
74 | 74 |
drilldown_x=self.drilldown_x, drilldown_y=self.drilldown_y, |
75 | 75 |
filters=copy.deepcopy(self.filters), loop=self.loop) |
76 | 76 | |
77 |
@classmethod |
|
78 |
def from_json(cls, d, request=None): |
|
77 |
@staticmethod |
|
78 |
def exists(visualization_obj, request=None): |
|
79 |
try: |
|
80 |
Visualization.get_cube(visualization_obj.parameters, request) |
|
81 |
return True |
|
82 |
except Http404: |
|
83 |
return False |
|
84 | ||
85 |
@staticmethod |
|
86 |
def get_cube(d, request=None): |
|
79 | 87 |
for warehouse in get_warehouses(request=request): |
80 | 88 |
if d['warehouse'] == warehouse.name: |
81 | 89 |
break |
... | ... | |
83 | 91 |
raise Http404('warehouse %s not found' % d['warehouse']) |
84 | 92 |
engine = Engine(warehouse) |
85 | 93 |
try: |
86 |
cube = engine[d['cube']]
|
|
94 |
return engine[d['cube']]
|
|
87 | 95 |
except KeyError: |
88 | 96 |
raise Http404('cube %s not found' % d['cube']) |
97 | ||
98 |
@classmethod |
|
99 |
def from_json(cls, d, request=None): |
|
100 |
cube = cls.get_cube(d, request) |
|
89 | 101 |
representation = d['representation'] |
90 | 102 |
measure = cube.measures[d['measure']] |
91 | 103 |
drilldown_x = cube.dimensions[d['drilldown_x']] if 'drilldown_x' in d else None |
bijoe/visualization/views.py | ||
---|---|---|
186 | 186 |
class VisualizationsView(views.AuthorizationMixin, ListView): |
187 | 187 |
template_name = 'bijoe/visualizations.html' |
188 | 188 |
model = models.Visualization |
189 |
context_object_name = 'visualizations' |
|
190 | ||
191 |
def get_context_data(self, **kwargs): |
|
192 |
ctx = super(VisualizationsView, self).get_context_data(**kwargs) |
|
193 |
ctx[self.context_object_name] = {v: Visualization.exists(v, request=self.request) |
|
194 |
for v in ctx[self.context_object_name]} |
|
195 |
return ctx |
|
196 | ||
189 | 197 | |
190 | 198 | |
191 | 199 |
class RenameVisualization(views.AuthorizationMixin, UpdateView): |
tests/test_schema2.py | ||
---|---|---|
1 | 1 |
import json |
2 | 2 |
import os |
3 | 3 | |
4 |
import mock |
|
4 | 5 |
import pytest |
5 | 6 | |
7 |
from bijoe.visualization.models import Visualization |
|
8 | ||
6 | 9 |
from utils import login, get_table |
7 | 10 | |
8 | 11 | |
... | ... | |
32 | 35 |
visualization_page = response.click(lambda x: x == visualization) |
33 | 36 |
assert 'big-msg-info' not in visualization_page |
34 | 37 |
assert schema2['tables'][visualization] == get_table(visualization_page) |
38 | ||
39 | ||
40 |
def test_missing_data(schema2, app, admin, visualization): |
|
41 |
login(app, admin) |
|
42 | ||
43 |
params = Visualization.objects.get(name=visualization).parameters |
|
44 |
params['cube'] = 'missing_cube' |
|
45 | ||
46 |
with mock.patch('bijoe.visualization.models.Visualization.parameters', |
|
47 |
new_callable=mock.PropertyMock) as mocked: |
|
48 |
mocked.return_value = params |
|
49 |
response = app.get('/') |
|
50 | ||
51 |
assert len(response.pyquery('ul li a.disabled')) == len(schema2['tables']) |
tox.ini | ||
---|---|---|
24 | 24 |
WebTest |
25 | 25 |
django-webtest<1.9.3 |
26 | 26 |
pyquery |
27 |
mock |
|
27 | 28 |
commands = |
28 | 29 |
dj111: py.test {posargs: --junitxml=test_{envname}_results.xml --cov-report xml --cov-report html --cov=bijoe tests/} |
29 | 30 |
[pytest] |
30 |
- |