schon/engine/core/validators.py
Egor fureunoir Gorbunov 9034551502 Features: 1) Add configurable options for BACKUP_DATABASE and BACKUP_MEDIA in system settings; 2) Enhance backup_task to handle selective backups and return status message;
Fixes: 1) Add exception handling for invalid image file dimensions in `validators.py`;

Extra: 1) Update settings categories to include new system options; 2) Improve code clarity in `backup_task` and `validators.py`.
2025-12-01 12:38:23 +03:00

19 lines
775 B
Python

from django.core.exceptions import ValidationError
from django.core.files.images import ImageFile, get_image_dimensions
from django.utils.translation import gettext_lazy as _
def validate_category_image_dimensions(
image: ImageFile, max_width: int | None = None, max_height: int | None = None
) -> None:
max_width = max_width or 7680
max_height = max_height or 4320
if image:
try:
width, height = get_image_dimensions(image.file) # type: ignore [arg-type]
except (FileNotFoundError, OSError, ValueError):
return
if int(width) > max_width or int(height) > max_height: # type: ignore [arg-type]
raise ValidationError(_(f"image dimensions should not exceed w{max_width} x h{max_height} pixels"))