Skip to content
Snippets Groups Projects
Commit 8ec96619 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[web][experiment][admin] Added action to delete all cached files related to selected cache

This will go through all results and inputs of all experiments
that are using this cache.
parent 1eb3103d
No related branches found
No related tags found
2 merge requests!2551.4.x,!239Delete cached files
Pipeline #
...@@ -532,6 +532,27 @@ def delete_file_on_fs(modeladmin, request, queryset): ...@@ -532,6 +532,27 @@ def delete_file_on_fs(modeladmin, request, queryset):
delete_file_on_fs.short_description = 'Delete files from the cache' delete_file_on_fs.short_description = 'Delete files from the cache'
def cascading_delete_file_on_fs(modeladmin, request, queryset):
'''
Delete the files contained in the cache
'''
for obj in queryset:
for block in obj.blocks.all():
experiment = block.experiment
for exp_block in experiment.blocks.all():
for result in exp_block.results.all():
if result.cache is not None:
result.cache.delete_files()
for input_ in exp_block.inputs.all():
if input_.cache is not None:
input_.cache.delete_files()
cascading_delete_file_on_fs.short_description = 'Delete files from the ' \
'selected and related caches'
class CachedFile(admin.ModelAdmin): class CachedFile(admin.ModelAdmin):
search_fields = [ search_fields = [
...@@ -555,7 +576,7 @@ class CachedFile(admin.ModelAdmin): ...@@ -555,7 +576,7 @@ class CachedFile(admin.ModelAdmin):
# to avoid very slow loading of cached files # to avoid very slow loading of cached files
raw_id_fields = ('blocks',) raw_id_fields = ('blocks',)
actions = [delete_file_on_fs] actions = [delete_file_on_fs, cascading_delete_file_on_fs]
def get_queryset(self, request): def get_queryset(self, request):
qs = super(CachedFile, self).get_queryset(request) qs = super(CachedFile, self).get_queryset(request)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment