Admin recipes
Tobias Kunze edited this page Nov 24, 2021
·
2 revisions
These recipes are too rough to land in the official documentation, but might come in handy regardless.
pretalx used to be really bad at deleting unused files (better now, but we can't just go around deleting old stuff, for reasons).
This script prints a list of known files that should be present. Put it in correct_files
:
# Collect correct_files
files = []
settings_keys = {"agenda_css_file", "cfp_css_file"}
for e in Event_SettingsStore.objects.filter(key__in=settings_keys).values_list(
"value", flat=True
):
files.append(e)
models = [
(DJCRMOrganiser, "dsgvo_document"),
(EventComInvoice, "invoice"),
(BlogPost, "image"),
(Event, "custom_css"),
(Event, "logo"),
(Event, "header_image"),
(SpeakerInformation, "resource"),
(User, "avatar"),
(Resource, "resource"),
(Answer, "answer_file"),
(Submission, "image"),
]
for model, field in models:
for obj in model.objects.filter(**{f"{field}__isnull": False}):
if getattr(obj, field):
files.append(getattr(obj, field).path)
with open("/tmp/correct_files", "w") as f:
f.write("\n".join(files))
Next, collect all existing files with fd:
fd -type f > pretalx_file_list
Then compare these two:
diff correct_files pretalx_file_list | grep '^>' | sed 's/^>\ //' > remove_these_files
Remove all cfp_uploads from remove_these_files
.
Then, sanity check the list and run xargs rm < remove_these_files
. I'm sure you have backups.