當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。