From 4cc3ef5b16a9b5f0597401a64d03db5b72d506ba Mon Sep 17 00:00:00 2001 From: Tomas Zigo Date: Tue, 21 Apr 2020 08:06:22 +0200 Subject: [PATCH] feat: validate template header logo image format --- apps/html_template_editor/validators.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/html_template_editor/validators.py b/apps/html_template_editor/validators.py index fd0676d2c..220b7ce5c 100644 --- a/apps/html_template_editor/validators.py +++ b/apps/html_template_editor/validators.py @@ -7,11 +7,19 @@ def validate_logo_image(image): max_width = 300 megabyte_limit = 5.0 * 1024 * 1024 + allowed_image_formats = ['JPEG', 'PNG'] - width, height = Image.open(image).size + img = Image.open(image) + width, height = img.size image_file_size = image.tell() + image_file_format = img.format + + if image_file_format not in allowed_image_formats: + raise ValidationError( + _("Allowed image format is %(image_formats)s "), + params={'image_formats': ', '.join(allowed_image_formats)}, + ) - print(width, image_file_size) if width > max_width: raise ValidationError( _("Width is larger than what is allowed %(max_width)s px"),