Merge branch 'bug/establishment_optimize' into 'develop'

logs and save extension for preview

See merge request gm/gm-backend!215
This commit is contained in:
Anton Gorbunov 2020-01-16 07:56:50 +00:00
commit 37a6ea8d1e

View File

@ -1,3 +1,5 @@
import os
from django.conf import settings
from django.core.management.base import BaseCommand
from django.db import transaction
@ -21,8 +23,13 @@ class Command(BaseCommand):
sorl_width_height = sorl_settings['geometry_string'].split('x')
if int(sorl_width_height[0]) > width or int(sorl_width_height[1]) > height:
_, file_ext = os.path.splitext(establishment.preview_image_url)
self.stdout.write(self.style.SUCCESS(f'Optimize: {establishment.preview_image_url}, extension: {file_ext}'))
establishment.preview_image_url = get_thumbnail(
file_=establishment.preview_image_url,
**sorl_settings
**sorl_settings,
format='PNG' if file_ext[1:] == 'png' else 'JPEG'
).url
establishment.save()