Esempio n. 1
0
 def to_python(self, value):
     """
     Validates that float() can be called on the input. Returns the result
     of float(). Returns None for empty values.
     """
     value = super(IntegerField, self).to_python(value)
     if value in validators.EMPTY_VALUES:
         return None
     if self.localize:
         value = formats.sanitize_separators(value)
     try:
         value = float(value)
     except (ValueError, TypeError):
         raise ValidationError(self.error_messages['invalid'])
     return value
Esempio n. 2
0
 def to_python(self, value):
     """
     Validates that float() can be called on the input. Returns the result
     of float(). Returns None for empty values.
     """
     value = super(IntegerField, self).to_python(value)
     if value in validators.EMPTY_VALUES:
         return None
     if self.localize:
         value = formats.sanitize_separators(value)
     try:
         value = float(value)
     except (ValueError, TypeError):
         raise ValidationError(self.error_messages['invalid'])
     return value
Esempio n. 3
0
 def to_python(self, value):
     """
     Validates that the input is a decimal number. Returns a Decimal
     instance. Returns None for empty values. Ensures that there are no more
     than max_digits in the number, and no more than decimal_places digits
     after the decimal point.
     """
     if value in validators.EMPTY_VALUES:
         return None
     if self.localize:
         value = formats.sanitize_separators(value)
     value = smart_str(value).strip()
     try:
         value = Decimal(value)
     except DecimalException:
         raise ValidationError(self.error_messages['invalid'])
     return value
Esempio n. 4
0
 def to_python(self, value):
     """
     Validates that the input is a decimal number. Returns a Decimal
     instance. Returns None for empty values. Ensures that there are no more
     than max_digits in the number, and no more than decimal_places digits
     after the decimal point.
     """
     if value in validators.EMPTY_VALUES:
         return None
     if self.localize:
         value = formats.sanitize_separators(value)
     value = smart_str(value).strip()
     try:
         value = Decimal(value)
     except DecimalException:
         raise ValidationError(self.error_messages['invalid'])
     return value