From dfcb9c525e3f5f564ac259b8dc315069e235fe1b Mon Sep 17 00:00:00 2001 From: sudan45 Date: Tue, 5 Mar 2024 11:51:29 +0545 Subject: [PATCH] Remove deleted widgets from export --- apps/analysis_framework/admin.py | 1 + apps/analysis_framework/dataloaders.py | 3 ++- apps/analysis_framework/export.py | 2 +- apps/analysis_framework/serializers.py | 5 +++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/analysis_framework/admin.py b/apps/analysis_framework/admin.py index 9c50badab6..d79b7151a8 100644 --- a/apps/analysis_framework/admin.py +++ b/apps/analysis_framework/admin.py @@ -55,6 +55,7 @@ class AFRelatedAdmin(JFModelAdmin): '__str__', linkify('analysis_framework'), ) autocomplete_fields = ('analysis_framework',) + list_filter = ['analysis_framework'] def get_queryset(self, request): return super().get_queryset(request).prefetch_related('analysis_framework') diff --git a/apps/analysis_framework/dataloaders.py b/apps/analysis_framework/dataloaders.py index c4508144a7..7182525f23 100644 --- a/apps/analysis_framework/dataloaders.py +++ b/apps/analysis_framework/dataloaders.py @@ -25,7 +25,8 @@ def load_widgets(keys, parent, **filters): **{ f'{parent}__in': keys, **filters, - } + }, + is_deleted=False ).exclude(widget_id__in=Widget.DEPRECATED_TYPES)\ .annotate(conditional_parent_widget_type=models.F('conditional_parent_widget__widget_id'))\ .order_by('order', 'id') diff --git a/apps/analysis_framework/export.py b/apps/analysis_framework/export.py index 1167b198ab..980c5615b0 100644 --- a/apps/analysis_framework/export.py +++ b/apps/analysis_framework/export.py @@ -27,7 +27,7 @@ def export_af_to_csv(af, file): writer = csv.DictWriter(file, fieldnames=AF_EXPORT_COLUMNS) writer.writeheader() - for widget in af.widget_set.order_by('widget_id'): + for widget in af.widget_set.filter(is_deleted=False).order_by('widget_id'): w_type = widget.widget_id w_title = widget.title diff --git a/apps/analysis_framework/serializers.py b/apps/analysis_framework/serializers.py index a29f3545a7..b3b613f264 100644 --- a/apps/analysis_framework/serializers.py +++ b/apps/analysis_framework/serializers.py @@ -386,7 +386,8 @@ def perform_nested_delete_or_update(self, pks_to_delete, model_class, instance, section=self.instance, # NOTE: Adding this additional filter just to make sure pk__in=pks_to_delete ) - qs.delete() + qs.update(is_deleted=True) + # qs.delete() # NOTE: This is a custom function (apps/user_resource/serializers.py::UserResourceSerializer) # This makes sure only scoped (individual AF) instances (widgets) are updated. @@ -560,7 +561,7 @@ def _delete_old_secondary_taggings(self, af, secondary_tagging): analysis_framework=af, section__isnull=True, # NOTE: section are null for secondary taggings ).exclude(pk__in=current_ids) # Exclude current provided widgets - qs_to_delete.delete() + qs_to_delete.update(is_deleted=True) def _save_secondary_taggings(self, af, secondary_tagging): # Create secondary tagging widgets (Primary/Section widgets are created using WritableNestedModelSerializer)