Skip to content

Commit 4cc3ef5

Browse files
committed
feat: validate template header logo image format
1 parent 2d586b2 commit 4cc3ef5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

apps/html_template_editor/validators.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@
77
def validate_logo_image(image):
88
max_width = 300
99
megabyte_limit = 5.0 * 1024 * 1024
10+
allowed_image_formats = ['JPEG', 'PNG']
1011

11-
width, height = Image.open(image).size
12+
img = Image.open(image)
13+
width, height = img.size
1214
image_file_size = image.tell()
15+
image_file_format = img.format
16+
17+
if image_file_format not in allowed_image_formats:
18+
raise ValidationError(
19+
_("Allowed image format is %(image_formats)s "),
20+
params={'image_formats': ', '.join(allowed_image_formats)},
21+
)
1322

14-
print(width, image_file_size)
1523
if width > max_width:
1624
raise ValidationError(
1725
_("Width is larger than what is allowed %(max_width)s px"),

0 commit comments

Comments
 (0)