0001-dataviz-get-request-when-possible-on-subfilters-upda.patch
combo/apps/dataviz/models.py | ||
---|---|---|
40 | 40 | |
41 | 41 |
from combo.data.library import register_cell_class |
42 | 42 |
from combo.data.models import CellBase, django_template_validator |
43 |
from combo.middleware import get_request |
|
43 | 44 |
from combo.utils import get_templated_url, requests, spooler |
44 | 45 | |
45 | 46 | |
... | ... | |
457 | 458 | |
458 | 459 |
@cached_property |
459 | 460 |
def request_context(self): |
460 |
if not hasattr(self, '_request'):
|
|
461 |
if not getattr(self, '_request', None):
|
|
461 | 462 |
raise MissingRequest |
462 | 463 | |
463 |
return RequestContext(self._request, self._request.extra_context)
|
|
464 |
return RequestContext(self._request, getattr(self._request, 'extra_context', {}))
|
|
464 | 465 | |
465 | 466 |
def parse_response(self, response, chart): |
466 | 467 |
# normalize axis to have a fake axis when there are no dimensions and |
... | ... | |
713 | 714 |
return self.statistic.filters + self.subfilters |
714 | 715 | |
715 | 716 |
def update_subfilters(self): |
717 |
self._request = get_request() |
|
716 | 718 |
response = self.get_statistic_data() |
717 | 719 |
try: |
718 | 720 |
response.raise_for_status() |
combo/apps/dataviz/views.py | ||
---|---|---|
57 | 57 |
if not form.is_valid(): |
58 | 58 |
return self.error(_('Wrong parameters.')) |
59 | 59 | |
60 |
request.extra_context = {} |
|
61 | 60 |
if request.GET.get('ctx'): |
62 | 61 |
try: |
63 | 62 |
request.extra_context = signing.loads(request.GET['ctx']) |
tests/test_dataviz.py | ||
---|---|---|
2566 | 2566 | |
2567 | 2567 |
refresh_statistics_data(cell.pk) |
2568 | 2568 |
assert len(bijoe_mock.call['requests']) == 1 |
2569 | ||
2570 | ||
2571 |
@with_httmock(new_api_mock) |
|
2572 |
def test_chartng_cell_subfilter_page_variable(new_api_statistics, app, admin_user, nocache): |
|
2573 |
page = Page.objects.create(title='One', slug='index', extra_variables={'foo': 'bar'}) |
|
2574 |
cell = ChartNgCell.objects.create(page=page, order=2, placeholder='content') |
|
2575 |
cell.statistic = Statistic.objects.get(slug='with-subfilter') |
|
2576 |
cell.save() |
|
2577 | ||
2578 |
app = login(app) |
|
2579 |
resp = app.get('/manage/pages/%s/' % page.id) |
|
2580 | ||
2581 |
# set filter value to page variable |
|
2582 |
field_prefix = 'cdataviz_chartngcell-%s-' % cell.id |
|
2583 |
resp.forms[1][field_prefix + 'other'] = 'variable:foo' |
|
2584 |
manager_submit_cell(resp.forms[1]) |
|
2585 | ||
2586 |
# change choice with subfilters |
|
2587 |
resp.forms[1][field_prefix + 'form'] = 'food-request' |
|
2588 |
manager_submit_cell(resp.forms[1]) |
|
2589 |
assert field_prefix + 'menu' in resp.forms[1].fields |
|
2569 |
- |