mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 00:49:16 +02:00
Delete existing thumbnails automatically when running
This commit is contained in:
parent
f400d2568b
commit
53b5c6261e
2 changed files with 24 additions and 1 deletions
|
@ -2,6 +2,7 @@ import click
|
|||
|
||||
from django.core.cache import cache
|
||||
from django.conf import settings
|
||||
from django.core.files.storage import default_storage
|
||||
|
||||
from versatileimagefield.image_warmer import VersatileImageFieldWarmer
|
||||
from versatileimagefield import settings as vif_settings
|
||||
|
@ -19,13 +20,23 @@ def media():
|
|||
|
||||
|
||||
@media.command("generate-thumbnails")
|
||||
def generate_thumbnails():
|
||||
@click.option("-d", "--delete", is_flag=True)
|
||||
def generate_thumbnails(delete):
|
||||
"""
|
||||
Generate thumbnails for all images (avatars, covers, etc.).
|
||||
|
||||
This can take a long time and generate a lot of I/O depending of the size
|
||||
of your library.
|
||||
"""
|
||||
click.echo("Deleting existing thumbnails…")
|
||||
if delete:
|
||||
try:
|
||||
# FileSystemStorage doesn't support deleting a non-empty directory
|
||||
# so we reimplemented a method to do so
|
||||
default_storage.force_delete("__sized__")
|
||||
except AttributeError:
|
||||
# backends doesn't support directory deletion
|
||||
pass
|
||||
MODELS = [
|
||||
(Attachment, "file", "attachment_square"),
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue