dataviz: pass request in context during page variable evaluation (#65348)
This commit is contained in:
parent
348f9b50bf
commit
eed78d8f6a
|
@ -460,7 +460,9 @@ class ChartNgCell(CellBase):
|
|||
if not hasattr(self, '_request'):
|
||||
raise MissingRequest
|
||||
|
||||
return RequestContext(self._request, self._request.extra_context)
|
||||
ctx = RequestContext(self._request, self._request.extra_context)
|
||||
ctx['request'] = self._request
|
||||
return ctx
|
||||
|
||||
def parse_response(self, response, chart):
|
||||
# normalize axis to have a fake axis when there are no dimensions and
|
||||
|
|
|
@ -12,6 +12,8 @@ $(function() {
|
|||
qs.push(chart_filters_form.serialize());
|
||||
if(extra_context)
|
||||
qs.push('ctx=' + extra_context);
|
||||
if (window.location.search)
|
||||
qs.push(window.location.search.slice(1));
|
||||
$.ajax({
|
||||
url : "{% url 'combo-dataviz-graph' cell=cell.id %}?" + qs.join('&'),
|
||||
type: 'GET',
|
||||
|
@ -35,7 +37,13 @@ $(function() {
|
|||
var chart_cell = $('#chart-{{cell.id}}').parent();
|
||||
var new_width = Math.floor($(chart_cell).width());
|
||||
var ratio = new_width / last_width;
|
||||
var qs = '?width=' + new_width
|
||||
var qs;
|
||||
if (window.location.search) {
|
||||
qs = window.location.search + '&';
|
||||
} else {
|
||||
qs = '?';
|
||||
}
|
||||
qs += 'width=' + new_width
|
||||
if(chart_filters_form)
|
||||
qs += '&' + chart_filters_form.serialize()
|
||||
if(extra_context)
|
||||
|
@ -46,7 +54,13 @@ $(function() {
|
|||
}
|
||||
}).trigger('combo:resize-graphs');
|
||||
$(window).on('combo:refresh-graphs', function() {
|
||||
var qs = '?width=' + last_width
|
||||
var qs;
|
||||
if (window.location.search) {
|
||||
qs = window.location.search + '&';
|
||||
} else {
|
||||
qs = '?';
|
||||
}
|
||||
qs += 'width=' + last_width
|
||||
if(chart_filters_form)
|
||||
qs += '&' + chart_filters_form.serialize()
|
||||
if(extra_context)
|
||||
|
|
|
@ -1849,6 +1849,7 @@ def test_chartng_cell_new_api_filter_params(app, new_api_statistics, nocache, fr
|
|||
slug='index',
|
||||
extra_variables={
|
||||
'custom_date': '{{ "2021-02-03"|parse_date }}',
|
||||
'from-request': '{{ request.GET.test }}',
|
||||
'not-a-date': 'not-a-date',
|
||||
'syntax-error': '{% for %}',
|
||||
},
|
||||
|
@ -1962,6 +1963,12 @@ def test_chartng_cell_new_api_filter_params(app, new_api_statistics, nocache, fr
|
|||
request = new_api_mock.call['requests'][-1]
|
||||
assert 'start' not in request.url
|
||||
|
||||
cell.time_range_start_template = 'from-request'
|
||||
cell.save()
|
||||
app.get(location + '?test=2022-05-17')
|
||||
request = new_api_mock.call['requests'][-1]
|
||||
assert 'start=2022-05-17' in request.url
|
||||
|
||||
|
||||
@with_httmock(new_api_mock)
|
||||
def test_chartng_cell_new_api_filter_params_month(new_api_statistics, nocache, freezer):
|
||||
|
|
Loading…
Reference in New Issue