schon/core/validators.py
Egor fureunoir Gorbunov 8fb4ca3362 Features: 1) Add type annotations for various models and methods; 2) Introduce refined graphene resolvers to enhance permission handling; 3) Include type checking suppression with # type: ignore for unsupported cases.
Fixes: 1) Correct `urlsafe_base64_encode` decoding logic in tests; 2) Fix queryset access issues in resolvers; 3) Address missing or incorrect imports across multiple files.

Extra: Improve code readability with consistent naming and formatting; Add `# noinspection` annotations to suppress IDE warnings; Update `pyproject.toml` to exclude `drf.py` in MyPy checks.
2025-06-18 16:38:07 +03:00

22 lines
704 B
Python

import re
from django.core.exceptions import ValidationError
from django.core.files.images import get_image_dimensions
from django.utils.translation import gettext_lazy as _
def validate_category_image_dimensions(image):
max_width = 99999
max_height = 99999
if image:
width, height = get_image_dimensions(image.file)
if width > max_width or height > max_height:
raise ValidationError(_(f"image dimensions should not exceed w{max_width} x h{max_height} pixels"))
def validate_phone_number(value, **_kwargs):
phone_regex = re.compile(r"^\+?1?\d{9,15}$")
if not phone_regex.match(value):
raise ValidationError(_("invalid phone number format"))