dataviz: avoid flagging extra time interval as unavailable (#62032)
This commit is contained in:
parent
02865103a9
commit
898bf1d6b5
|
@ -70,6 +70,9 @@ class ChartFiltersMixin:
|
|||
choices = [(option['id'], option['label']) for option in filter_['options']]
|
||||
initial = cell.filter_params.get(filter_id, filter_.get('default'))
|
||||
|
||||
if filter_id == 'time_interval':
|
||||
self.extend_time_interval_choices(choices)
|
||||
|
||||
possible_choices = {choice[0] for choice in choices}
|
||||
for choice in initial if isinstance(initial, list) else [initial]:
|
||||
if choice and choice not in possible_choices:
|
||||
|
@ -86,16 +89,15 @@ class ChartFiltersMixin:
|
|||
)
|
||||
fields[filter_id].is_filter_field = True
|
||||
|
||||
# extend time interval choices if possible
|
||||
if 'time_interval' in fields:
|
||||
choice_ids = {choice_id for choice_id, _ in fields['time_interval'].choices}
|
||||
if 'day' in choice_ids:
|
||||
for choice in self.time_intervals:
|
||||
if choice[0] not in choice_ids:
|
||||
fields['time_interval'].choices.append(choice)
|
||||
|
||||
return fields
|
||||
|
||||
def extend_time_interval_choices(self, choices):
|
||||
choice_ids = {choice_id for choice_id, _ in choices}
|
||||
if 'day' in choice_ids:
|
||||
for choice in self.time_intervals:
|
||||
if choice[0] not in choice_ids:
|
||||
choices.append(choice)
|
||||
|
||||
|
||||
class ChartNgForm(ChartFiltersMixin, forms.ModelForm):
|
||||
class Meta:
|
||||
|
|
|
@ -1814,7 +1814,15 @@ def test_chartng_cell_new_api_aggregation(new_api_statistics, app, admin_user, n
|
|||
assert chart.raw_series[1][0][:8] == [2, 0, 0, 0, 0, 0, 0, 2]
|
||||
|
||||
time_interval_field.value = 'month'
|
||||
resp.form.submit()
|
||||
resp = resp.form.submit().follow()
|
||||
time_interval_field = resp.form['cdataviz_chartngcell-%s-time_interval' % cell.id]
|
||||
assert time_interval_field.options == [
|
||||
('day', False, 'Day'),
|
||||
('week', False, 'Week'),
|
||||
('month', True, 'Month'), # month choice is selected
|
||||
('year', False, 'Year'),
|
||||
('weekday', False, 'Week day'),
|
||||
]
|
||||
cell.refresh_from_db()
|
||||
|
||||
chart = cell.get_chart()
|
||||
|
|
Loading…
Reference in New Issue