def __call__(self, value: Union[int, float]): if not isinstance(value, (int, float)): raise ValidationError( "Value must be a numeric value and is required") if value > self.max_value: raise ValidationError( f"Value should be less or equal to {self.max_value}")
def validate_ipv6_address(value: Any): """ A validator to validate whether the given value is valid IPv6Address or not. :raises ValidationError: if value is invalid IPv6Address. """ try: ipaddress.IPv6Address(value) except ValueError: raise ValidationError(f"'{value}' is not a valid IPv6 address.")
def validate(self, value: Any): """ Validate whether given value is valid :param value: Value to be validation :raises ValidationError: If validator check is not passed """ for v in self.validators: if self.null and value is None: continue try: if isinstance(value, Enum): v(value.value) else: v(value) except ValidationError as exc: raise ValidationError(f"{self.model_field_name}: {exc}")
def dict_or_list(value: Union[dict, list]): if not isinstance(value, (dict, list)): raise ValidationError("Value must be a dict or list.")
def __init__(self, max_value: Union[int, float]): if not isinstance(max_value, (int, float)): raise ValidationError( "Value must be a numeric value and is required") self.max_value = max_value
def __call__(self, value: str): if value is None: raise ValidationError("Value must not be None") if len(value) < self.min_length: raise ValidationError( f"Length of '{value}' {len(value)} < {self.min_length}")
def __call__(self, value: Any): if not self.regex.match(value): raise ValidationError( f"Value '{value}' does not match regex '{self.regex.pattern}'")
def __call__(self, value: int): if value < 0: raise ValidationError( "Ensure this value is greater than or equal to 0.")
def non_negative_validator(value: int): if value < 0: raise ValidationError(f"Value is negative: {value}")
def __call__(self, value: int): if value not in constants.CLAN_MEMBER_RANKS: raise ValidationError(f"Value '{value}' is not a valid clan rank")
def __call__(self, value: int): if value not in constants.PLATFORMS: raise ValidationError(f"Value '{value}' is not a valid platform")