Fixes: (1) Removed all `# type: ignore` annotations across the codebase; (2) Fixed usage of Django Model methods by eliminating unnecessary `# type: ignore` directives; (3) Adjusted usage of functions like `get()` to align with method expectations, removing incorrect comments; Extra: (1) Deleted `pyrightconfig.json` as part of migration to a stricter type-checked environment; (2) Minor code cleanup, including formatting changes and refactoring import statements in adherence to PEP8 recommendations.
23 lines
789 B
Python
23 lines
789 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)
|
|
except (FileNotFoundError, OSError, ValueError):
|
|
return
|
|
|
|
if int(width) > max_width or int(height) > max_height:
|
|
raise ValidationError(
|
|
_(
|
|
f"image dimensions should not exceed w{max_width} x h{max_height} pixels"
|
|
)
|
|
)
|