本文整理汇总了Python中django.utils.formats.localize_input方法的典型用法代码示例。如果您正苦于以下问题:Python formats.localize_input方法的具体用法?Python formats.localize_input怎么用?Python formats.localize_input使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.formats
的用法示例。
在下文中一共展示了formats.localize_input方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _format_value
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import localize_input [as 别名]
def _format_value(self, value):
if self.is_localized:
return formats.localize_input(value)
return value
示例2: format_value
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import localize_input [as 别名]
def format_value(self, value):
"""
Return a value as it should appear when rendered in a template.
"""
if value == '' or value is None:
return None
if self.is_localized:
return formats.localize_input(value)
return str(value)
示例3: format_value
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import localize_input [as 别名]
def format_value(self, value):
"""
Return a value as it should appear when rendered in a template.
"""
if value == '' or value is None:
return None
if self.is_localized:
return formats.localize_input(value)
return force_text(value)
示例4: format_value
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import localize_input [as 别名]
def format_value(self, value):
"""
Return a value as it should appear when rendered in a template.
Missing method of django.forms.widgets.Widget class
"""
if value == '' or value is None:
return None
return formats.localize_input(value, self.format)
示例5: _has_changed
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import localize_input [as 别名]
def _has_changed(self, initial, data):
# If our field has show_hidden_initial=True, initial will be a string
# formatted by HiddenInput using formats.localize_input, which is not
# necessarily the format used for this widget. Attempt to convert it.
try:
input_format = formats.get_format('DATE_INPUT_FORMATS')[0]
initial = datetime.datetime.strptime(initial, input_format).date()
except (TypeError, ValueError):
pass
return super(DateInput, self)._has_changed(self._format_value(initial), data)
示例6: format_value
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import localize_input [as 别名]
def format_value(self, value):
if self.format and \
isinstance(self.format, Promise):
return formats.localize_input(value, force_text(self.format))
else:
return super().format_value(value=value)
示例7: to_representation
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import localize_input [as 别名]
def to_representation(self, value):
coerce_to_string = getattr(self, 'coerce_to_string', api_settings.COERCE_DECIMAL_TO_STRING)
if not isinstance(value, decimal.Decimal):
value = decimal.Decimal(six.text_type(value).strip())
quantized = self.quantize(value)
if not coerce_to_string:
return quantized
if self.localize:
return localize_input(quantized)
return '{0:f}'.format(quantized)
示例8: test_floatfield_changed
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import localize_input [as 别名]
def test_floatfield_changed(self):
f = FloatField()
n = 4.35
self.assertFalse(f.has_changed(n, '4.3500'))
with translation.override('fr'), self.settings(USE_L10N=True):
f = FloatField(localize=True)
localized_n = formats.localize_input(n) # -> '4,35' in French
self.assertFalse(f.has_changed(n, localized_n))
示例9: test_decimalfield_changed
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import localize_input [as 别名]
def test_decimalfield_changed(self):
f = DecimalField(max_digits=2, decimal_places=2)
d = decimal.Decimal("0.1")
self.assertFalse(f.has_changed(d, '0.10'))
self.assertTrue(f.has_changed(d, '0.101'))
with translation.override('fr'), self.settings(USE_L10N=True):
f = DecimalField(max_digits=2, decimal_places=2, localize=True)
localized_d = formats.localize_input(d) # -> '0,1' in French
self.assertFalse(f.has_changed(d, localized_d))
示例10: format_value
# 需要导入模块: from django.utils import formats [as 别名]
# 或者: from django.utils.formats import localize_input [as 别名]
def format_value(self, value):
"""
返回在模板中呈现时应该出现的值。
"""
if value == '' or value is None:
return None
if self.is_localized:
return formats.localize_input(value)
return str(value)