From aa12a269d184577f025aceeb6139599818f44cba Mon Sep 17 00:00:00 2001 From: sudan45 Date: Mon, 23 Sep 2024 14:46:19 +0545 Subject: [PATCH 1/3] Fix json export and exportable --- apps/analysis_framework/serializers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/analysis_framework/serializers.py b/apps/analysis_framework/serializers.py index 1605a637ab..6772c49674 100644 --- a/apps/analysis_framework/serializers.py +++ b/apps/analysis_framework/serializers.py @@ -580,6 +580,12 @@ def _save_secondary_taggings(self, af, secondary_tagging): # Overwriting AF on save serializer.save(analysis_framework=af) + def _delete_exportable_widgets(self, af): + exportable_qs = Exportable.objects.filter( + analysis_framework=af + ) + exportable_qs.delete() + def _delete_old_prediction_tags_mapping(self, af, prediction_tags_mapping): current_ids = [ mapping['id'] @@ -643,6 +649,8 @@ def update(self, instance, validated_data): validated_data.pop('prediction_tags_mapping', None) secondary_tagging = self.initial_data.get('secondary_tagging', None) prediction_tags_mapping = self.initial_data.get('prediction_tags_mapping', None) + + self._delete_exportable_widgets(instance) # Update AF instance = super().update(instance, validated_data) # Update secondary_tagging From f59ecb22aec952a5e7f420d50fd163ded2b0a737 Mon Sep 17 00:00:00 2001 From: sudan45 Date: Tue, 24 Sep 2024 11:02:12 +0545 Subject: [PATCH 2/3] Remove exportable widegts key --- apps/analysis_framework/serializers.py | 14 +++++++------- apps/export/entries/json_exporter.py | 8 ++++++-- apps/export/tasks/tasks_entries.py | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/apps/analysis_framework/serializers.py b/apps/analysis_framework/serializers.py index 6772c49674..34cdd78a07 100644 --- a/apps/analysis_framework/serializers.py +++ b/apps/analysis_framework/serializers.py @@ -580,11 +580,11 @@ def _save_secondary_taggings(self, af, secondary_tagging): # Overwriting AF on save serializer.save(analysis_framework=af) - def _delete_exportable_widgets(self, af): - exportable_qs = Exportable.objects.filter( - analysis_framework=af - ) - exportable_qs.delete() + # def _delete_exportable_widgets(self, af): + # exportable_qs = Exportable.objects.filter( + # analysis_framework=af + # ) + # exportable_qs.delete() def _delete_old_prediction_tags_mapping(self, af, prediction_tags_mapping): current_ids = [ @@ -649,8 +649,6 @@ def update(self, instance, validated_data): validated_data.pop('prediction_tags_mapping', None) secondary_tagging = self.initial_data.get('secondary_tagging', None) prediction_tags_mapping = self.initial_data.get('prediction_tags_mapping', None) - - self._delete_exportable_widgets(instance) # Update AF instance = super().update(instance, validated_data) # Update secondary_tagging @@ -664,6 +662,8 @@ def update(self, instance, validated_data): if instance.created_by_id and not instance.members.filter(id=instance.created_by_id).exists(): owner_role = instance.get_or_create_owner_role() instance.add_member(instance.created_by, owner_role) + + # self._delete_exportable_widgets(instance) ProjectChangeManager.log_framework_update(instance.pk, self.context['request'].user) self._post_save(instance) return instance diff --git a/apps/export/entries/json_exporter.py b/apps/export/entries/json_exporter.py index 34053d74d6..bd97e327ab 100644 --- a/apps/export/entries/json_exporter.py +++ b/apps/export/entries/json_exporter.py @@ -8,8 +8,12 @@ def __init__(self, is_preview=False): self.is_preview = is_preview self.data = {} - def load_exportables(self, exportables): - self.exportables = exportables + def load_exportables(self, exportables, analysis_framework): + widgets_key = Widget.objects.filter(analysis_framework=analysis_framework).values_list( + 'key', + flat=True + ) + self.exportables = exportables.filter(widget_key__in=widgets_key) self.widget_ids = [] self.data['widgets'] = [] diff --git a/apps/export/tasks/tasks_entries.py b/apps/export/tasks/tasks_entries.py index 60888c44ed..9d8cd185d7 100644 --- a/apps/export/tasks/tasks_entries.py +++ b/apps/export/tasks/tasks_entries.py @@ -123,7 +123,7 @@ def export_entries(export): elif export_type == Export.ExportType.JSON: export_data = JsonExporter(is_preview=is_preview)\ - .load_exportables(exportables)\ + .load_exportables(exportables, project.analysis_framework)\ .add_entries(entries_qs)\ .export() From 123ea8097625e6770a991627dabad067d9db53de Mon Sep 17 00:00:00 2001 From: sudan45 Date: Wed, 25 Sep 2024 10:35:45 +0545 Subject: [PATCH 3/3] Remove commented code --- apps/analysis_framework/serializers.py | 7 ------- apps/export/entries/json_exporter.py | 2 ++ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/apps/analysis_framework/serializers.py b/apps/analysis_framework/serializers.py index 34cdd78a07..c25979a75c 100644 --- a/apps/analysis_framework/serializers.py +++ b/apps/analysis_framework/serializers.py @@ -580,12 +580,6 @@ def _save_secondary_taggings(self, af, secondary_tagging): # Overwriting AF on save serializer.save(analysis_framework=af) - # def _delete_exportable_widgets(self, af): - # exportable_qs = Exportable.objects.filter( - # analysis_framework=af - # ) - # exportable_qs.delete() - def _delete_old_prediction_tags_mapping(self, af, prediction_tags_mapping): current_ids = [ mapping['id'] @@ -663,7 +657,6 @@ def update(self, instance, validated_data): owner_role = instance.get_or_create_owner_role() instance.add_member(instance.created_by, owner_role) - # self._delete_exportable_widgets(instance) ProjectChangeManager.log_framework_update(instance.pk, self.context['request'].user) self._post_save(instance) return instance diff --git a/apps/export/entries/json_exporter.py b/apps/export/entries/json_exporter.py index bd97e327ab..d1632a161f 100644 --- a/apps/export/entries/json_exporter.py +++ b/apps/export/entries/json_exporter.py @@ -9,10 +9,12 @@ def __init__(self, is_preview=False): self.data = {} def load_exportables(self, exportables, analysis_framework): + # get all widget key name in list widgets_key = Widget.objects.filter(analysis_framework=analysis_framework).values_list( 'key', flat=True ) + # exclude widgets_key which are not in exportables table self.exportables = exportables.filter(widget_key__in=widgets_key) self.widget_ids = []