Skip to content

Commit

Permalink
Remove deleted widgets from export
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed May 7, 2024
1 parent 84fae41 commit dfcb9c5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/analysis_framework/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion apps/analysis_framework/dataloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion apps/analysis_framework/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions apps/analysis_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit dfcb9c5

Please sign in to comment.