Ejemplo n.º 1
0
    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}")
Ejemplo n.º 2
0
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.")
Ejemplo n.º 3
0
    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}")
Ejemplo n.º 4
0
 def dict_or_list(value: Union[dict, list]):
     if not isinstance(value, (dict, list)):
         raise ValidationError("Value must be a dict or list.")
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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}")
Ejemplo n.º 7
0
 def __call__(self, value: Any):
     if not self.regex.match(value):
         raise ValidationError(
             f"Value '{value}' does not match regex '{self.regex.pattern}'")
Ejemplo n.º 8
0
 def __call__(self, value: int):
     if value < 0:
         raise ValidationError(
             "Ensure this value is greater than or equal to 0.")
Ejemplo n.º 9
0
def non_negative_validator(value: int):
    if value < 0:
        raise ValidationError(f"Value is negative: {value}")
Ejemplo n.º 10
0
 def __call__(self, value: int):
     if value not in constants.CLAN_MEMBER_RANKS:
         raise ValidationError(f"Value '{value}' is not a valid clan rank")
Ejemplo n.º 11
0
 def __call__(self, value: int):
     if value not in constants.PLATFORMS:
         raise ValidationError(f"Value '{value}' is not a valid platform")