本文整理匯總了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)