当前位置: 首页>>代码示例>>Python>>正文


Python formats.sanitize_separators方法代码示例

本文整理汇总了Python中django.utils.formats.sanitize_separators方法的典型用法代码示例。如果您正苦于以下问题:Python formats.sanitize_separators方法的具体用法?Python formats.sanitize_separators怎么用?Python formats.sanitize_separators使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.formats的用法示例。


在下文中一共展示了formats.sanitize_separators方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: to_python

# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import sanitize_separators [as 别名]
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 self.empty_values:
            return None
        if self.localize:
            value = formats.sanitize_separators(value)
        value = smart_text(value).strip()
        try:
            value = Decimal(value)
        except DecimalException:
            raise ValidationError(self.error_messages['invalid'], code='invalid')
        return value 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:19,代码来源:fields.py

示例2: to_python

# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import sanitize_separators [as 别名]
def to_python(self, value):
        """
        Validate that int() can be called on the input. Return the result
        of int() or None for empty values.
        """
        value = super().to_python(value)
        if value in self.empty_values:
            return None
        if self.localize:
            value = formats.sanitize_separators(value)
        # Strip trailing decimal and zeros.
        try:
            value = int(self.re_decimal.sub('', str(value)))
        except (ValueError, TypeError):
            raise ValidationError(self.error_messages['invalid'], code='invalid')
        return value 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:18,代码来源:fields.py

示例3: to_python

# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import sanitize_separators [as 别名]
def to_python(self, value):
        """
        Validates that int() can be called on the input. Returns the result
        of int(). Returns None for empty values.
        """
        value = super(IntegerField, self).to_python(value)
        if value in self.empty_values:
            return None
        if self.localize:
            value = formats.sanitize_separators(value)
        # Strip trailing decimal and zeros.
        try:
            value = int(self.re_decimal.sub('', force_text(value)))
        except (ValueError, TypeError):
            raise ValidationError(self.error_messages['invalid'], code='invalid')
        return value 
开发者ID:Yeah-Kun,项目名称:python,代码行数:18,代码来源:fields.py

示例4: to_python

# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import sanitize_separators [as 别名]
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_text(value).strip()
        try:
            value = Decimal(value)
        except DecimalException:
            raise ValidationError(self.error_messages['invalid'])
        return value 
开发者ID:blackye,项目名称:luscan-devel,代码行数:19,代码来源:fields.py

示例5: to_python

# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import sanitize_separators [as 别名]
def to_python(self, value):
        """
        Validates that int() can be called on the input. Returns the result
        of int(). Returns None for empty values.
        """
        value = super(IntegerField, self).to_python(value)
        if value in self.empty_values:
            return None
        if self.localize:
            value = formats.sanitize_separators(value)
        # Strip trailing decimal and zeros.
        try:
            value = int(self.re_decimal.sub('', str(value)))
        except (ValueError, TypeError):
            raise ValidationError(self.error_messages['invalid'], code='invalid')
        return value 
开发者ID:drexly,项目名称:openhgsenti,代码行数:18,代码来源:fields.py

示例6: to_internal_value

# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import sanitize_separators [as 别名]
def to_internal_value(self, data):
        """
        Validate that the input is a decimal number and return a Decimal
        instance.
        """

        data = smart_text(data).strip()

        if self.localize:
            data = sanitize_separators(data)

        if len(data) > self.MAX_STRING_LENGTH:
            self.fail('max_string_length')

        try:
            value = decimal.Decimal(data)
        except decimal.DecimalException:
            self.fail('invalid')

        # Check for NaN. It is the only value that isn't equal to itself,
        # so we can use this to identify NaN values.
        if value != value:
            self.fail('invalid')

        # Check for infinity and negative infinity.
        if value in (decimal.Decimal('Inf'), decimal.Decimal('-Inf')):
            self.fail('invalid')

        return self.quantize(self.validate_precision(value)) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:31,代码来源:fields.py


注:本文中的django.utils.formats.sanitize_separators方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。