care.utils.models.validators module¶
- class JSONFieldSchemaValidator(*args, **kwargs)¶
Bases:
objectBased on the JSON Schema Validator at https://github.com/wblxyxolbkhv/django-json-field-schema-validator
- deconstruct()¶
Return a 3-tuple of class import path, positional arguments, and keyword arguments.
- class UsernameValidator(*args, **kwargs)¶
Bases:
RegexValidator- regex = '^(?!.*[._-]{2})[a-z0-9](?:[a-z0-9._-]{2,14}[a-z0-9])$'¶
- message = "Username must be 4 to 16 characters long. It may only contain lowercase alphabets, numbers, underscores, hyphens and dots. It shouldn't start or end with underscores, hyphens or dots. It shouldn't contain consecutive underscores, hyphens or dots."¶
- flags = 256¶
- deconstruct()¶
Return a 3-tuple of class import path, positional arguments, and keyword arguments.
- class PhoneNumberValidator(*args, **kwargs)¶
Bases:
RegexValidatorValidate phone numbers against one or more allowed types.
Any one of the specified types passed to the validator is considered sufficient for the value to be valid.
Allowed types:
mobile(Indian XOR International)indian_mobile(Indian only)international_mobile(International only)landline(Indian only)support(Indian only)
Example usage:
field = models.CharField( validators=[ PhoneNumberValidator(types=("mobile", "landline", "support")) ] )
- indian_mobile_number_regex = '^(?=^\\+91)(^\\+91[6-9]\\d{9}$)'¶
- international_mobile_number_regex = '^(?!^\\+91)(^\\+\\d{1,3}\\d{8,14}$)'¶
- landline_number_regex = '^\\+91[2-9]\\d{7,9}$'¶
- support_number_regex = '^(1800|1860)\\d{6,7}$'¶
- regex_map = {'indian_mobile': '^(?=^\\+91)(^\\+91[6-9]\\d{9}$)', 'international_mobile': '^(?!^\\+91)(^\\+\\d{1,3}\\d{8,14}$)', 'landline': '^\\+91[2-9]\\d{7,9}$', 'mobile': '^(?=^\\+91)(^\\+91[6-9]\\d{9}$)|^(?!^\\+91)(^\\+\\d{1,3}\\d{8,14}$)', 'support': '^(1800|1860)\\d{6,7}$'}¶
- deconstruct()¶
Return a 3-tuple of class import path, positional arguments, and keyword arguments.
- class DenominationValidator(*args, **kwargs)¶
Bases:
objectThis validator is used to validate string inputs with denominations. for example: 1 mg, 1.5 ml, 200 mg etc.
- __init__(min_amount: int | float, max_amount: int | float, units: Iterable[str], allow_floats: bool = True, precision: int = 2)¶
- deconstruct()¶
Return a 3-tuple of class import path, positional arguments, and keyword arguments.
- class MiddlewareDomainAddressValidator(*args, **kwargs)¶
Bases:
RegexValidator- regex = '^(?!https?:\\/\\/)[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)*\\.[a-zA-Z]{2,}$'¶
- code = 'invalid_domain_name'¶
- message = 'The domain name is invalid. It should not start with scheme and should not end with a trailing slash.'¶
- class ImageSizeValidator(*args, **kwargs)¶
Bases:
object- message: dict[str, str] = {'aspect_ratio': 'Image aspect ratio must be one of the following: %(aspect_ratio)s.', 'max_height': 'Image height is greater than the maximum allowed height of %(max_height)s pixels.', 'max_size': 'Image size is greater than the maximum allowed size of %(max_size)s.', 'max_width': 'Image width is greater than the maximum allowed width of %(max_width)s pixels.', 'min_height': 'Image height is less than the minimum allowed height of %(min_height)s pixels.', 'min_size': 'Image size is less than the minimum allowed size of %(min_size)s.', 'min_width': 'Image width is less than the minimum allowed width of %(min_width)s pixels.'}¶
- __init__(min_width: int | None = None, max_width: int | None = None, min_height: int | None = None, max_height: int | None = None, aspect_ratio: list[float] | None = None, min_size: int | None = None, max_size: int | None = None) None¶
- deconstruct()¶
Return a 3-tuple of class import path, positional arguments, and keyword arguments.
- parse_file_extension(file_name: str, max_extensions: int = 1) list[str]¶
Extract up to max_extensions file extensions.
“file.tar.gz” -> [‘tar’, ‘gz’]
“file.tar.bz2.xz” (max 3) -> [‘tar’, ‘bz2’, ‘xz’]
“file” -> []
Returns a list of extensions in lowercase (without the dot).
- class FileNameValidator(max_length: int = 255, max_extensions: int = 1, allowed_extensions: set[str] | None = None, blocked_extensions: set[str] | None = None)¶
Bases:
objectThis validator is used to validate the file name length and extension. - File name length should not exceed max_length characters. - File name should not start with a dot. - File outermost extension should not be in blocked_extensions if provided. - File outermost extension should be in allowed_extensions if provided.