-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1478 from the-deep/feature/update-viz-setting-and…
…-widgets Feature/update viz setting and widgets
- Loading branch information
Showing
8 changed files
with
200 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Generated by Django 3.2.17 on 2024-02-22 05:02 | ||
from django.db import migrations | ||
import copy | ||
|
||
|
||
def analysis_framework_widgets_mapping(apps, schema_editor): | ||
AnalysisFramework = apps.get_model('analysis_framework', 'AnalysisFramework') | ||
af_qs = AnalysisFramework.objects.filter(properties__isnull=False) | ||
for af in af_qs: | ||
if af.properties == {}: | ||
continue | ||
new_widget_config = af.properties | ||
# Remove super legacy config | ||
new_widget_config.pop('old_stats_config', None) | ||
|
||
# For reassurance | ||
new_widget_config = copy.deepcopy(new_widget_config) | ||
|
||
# Migrate legacy config to latest | ||
# -- Widget1D | ||
if 'widget_1d' not in new_widget_config['stats_config']: | ||
new_widget_config['widget_1d'] = [ | ||
{'pk': new_widget_config['stats_config'][key]['pk']} | ||
for key in [ | ||
'widget1d' | ||
] | ||
if key in new_widget_config | ||
] | ||
|
||
# -- Widget2D | ||
if 'widget_2d' not in new_widget_config['stats_config']: | ||
new_widget_config['widget_2d'] = [ | ||
{'pk': new_widget_config['stats_config'][key]['pk']} | ||
for key in [ | ||
'widget2d' | ||
] | ||
if key in new_widget_config | ||
] | ||
|
||
# -- Multiselect | ||
if 'multiselect_widgets' not in new_widget_config['stats_config']: | ||
new_widget_config['multiselect_widgets'] = [ | ||
{'pk': new_widget_config['stats_config'][key]['pk']} | ||
for key in [ | ||
'specific_needs_groups_widget', | ||
'demographic_groups_widget' | ||
] | ||
if key in new_widget_config | ||
] | ||
|
||
# -- Organigram | ||
if 'organigram_widget' not in new_widget_config['stats_config']: | ||
new_widget_config['organigram_widget'] = [ | ||
{'pk': new_widget_config['stats_config'][key]['pk']} | ||
for key in [ | ||
'affected_groups_widget' | ||
] | ||
if key in new_widget_config | ||
] | ||
|
||
legacy_widget_keys = [ | ||
'affected_groups_widget', | ||
'demographic_groups_widget', | ||
'specific_needs_groups_widget', | ||
] | ||
for widget_key in legacy_widget_keys: | ||
new_widget_config['stats_config'].pop(widget_key, None) | ||
|
||
af.properties = new_widget_config | ||
af.save(update_fields=('properties',)) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('analysis_framework', '0040_auto_20231109_1208'), | ||
] | ||
operations = [ | ||
migrations.RunPython( | ||
analysis_framework_widgets_mapping, | ||
reverse_code=migrations.RunPython.noop | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.