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

[web][experiments][admin] Added action to delete content from a cache entry

Also remove the default delete action which should not be used
for the CachedFile objects.
parent f5a0aa64
No related branches found
No related tags found
2 merge requests!2551.4.x,!239Delete cached files
......@@ -520,6 +520,18 @@ admin.site.register(ResultModel, Result)
#----------------------------------------------------------
def delete_file_on_fs(modeladmin, request, queryset):
'''
Delete the files contained in the cache
'''
for obj in queryset:
obj.delete_files()
delete_file_on_fs.short_description = 'Delete files from the cache'
class CachedFile(admin.ModelAdmin):
search_fields = [
......@@ -543,10 +555,18 @@ class CachedFile(admin.ModelAdmin):
# to avoid very slow loading of cached files
raw_id_fields = ('blocks',)
actions = [delete_file_on_fs]
def get_queryset(self, request):
qs = super(CachedFile, self).get_queryset(request)
return qs.annotate(date=Max('blocks__start_date'))
def get_actions(self, request):
actions = super(CachedFile, self).get_actions(request)
if 'delete_selected' in actions:
del actions['delete_selected']
return actions
def date(self, obj):
return obj.date
......
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