2018-07-18 13:37:07 +00:00
|
|
|
"""
|
|
|
|
Compute different sizes of image used for Album covers and User avatars
|
|
|
|
"""
|
|
|
|
|
|
|
|
from versatileimagefield.image_warmer import VersatileImageFieldWarmer
|
|
|
|
|
2019-11-25 08:49:06 +00:00
|
|
|
from funkwhale_api.common.models import Attachment
|
2018-07-18 13:37:07 +00:00
|
|
|
|
|
|
|
|
2019-11-25 08:49:06 +00:00
|
|
|
MODELS = [
|
|
|
|
(Attachment, "file", "attachment_square"),
|
|
|
|
]
|
2018-07-18 13:37:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main(command, **kwargs):
|
|
|
|
for model, attribute, key_set in MODELS:
|
|
|
|
qs = model.objects.exclude(**{"{}__isnull".format(attribute): True})
|
|
|
|
qs = qs.exclude(**{attribute: ""})
|
|
|
|
warmer = VersatileImageFieldWarmer(
|
|
|
|
instance_or_queryset=qs,
|
|
|
|
rendition_key_set=key_set,
|
|
|
|
image_attr=attribute,
|
|
|
|
verbose=True,
|
|
|
|
)
|
|
|
|
command.stdout.write(
|
|
|
|
"Creating images for {} / {}".format(model.__name__, attribute)
|
|
|
|
)
|
|
|
|
num_created, failed_to_create = warmer.warm()
|
|
|
|
command.stdout.write(
|
|
|
|
" {} created, {} in error".format(num_created, len(failed_to_create))
|
|
|
|
)
|