Python django.utils.formats.localize_input() Examples
The following are 27
code examples of django.utils.formats.localize_input().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.utils.formats
, or try the search function
.
Example #1
Source File: widgets.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
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('DATETIME_INPUT_FORMATS')[0] initial = datetime.datetime.strptime(initial, input_format) except (TypeError, ValueError): pass return super(DateTimeInput, self)._has_changed(self._format_value(initial), data)
Example #2
Source File: widgets.py From simpleui with MIT License | 5 votes |
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)
Example #3
Source File: widgets.py From simpleui with MIT License | 5 votes |
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)
Example #4
Source File: test_decimalfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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))
Example #5
Source File: test_floatfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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))
Example #6
Source File: test_decimalfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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))
Example #7
Source File: test_floatfield.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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))
Example #8
Source File: fields.py From Dailyfresh-B2C with Apache License 2.0 | 5 votes |
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)
Example #9
Source File: widgets.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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)
Example #10
Source File: widgets.py From python2017 with MIT License | 5 votes |
def format_value(self, value): if value is not None: # localize_input() returns str on Python 2. return force_text(formats.localize_input(value, self.format or formats.get_format(self.format_key)[0]))
Example #11
Source File: widgets.py From python2017 with MIT License | 5 votes |
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)
Example #12
Source File: widgets.py From openhgsenti with Apache License 2.0 | 5 votes |
def _format_value(self, value): return formats.localize_input(value, self.format or formats.get_format(self.format_key)[0])
Example #13
Source File: widgets.py From openhgsenti with Apache License 2.0 | 5 votes |
def _format_value(self, value): if self.is_localized: return formats.localize_input(value) return value
Example #14
Source File: widgets.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
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('TIME_INPUT_FORMATS')[0] initial = datetime.datetime.strptime(initial, input_format).time() except (TypeError, ValueError): pass return super(TimeInput, self)._has_changed(self._format_value(initial), data) # Defined at module level so that CheckboxInput is picklable (#17976)
Example #15
Source File: widgets.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def _format_value(self, value): if self.is_localized: return formats.localize_input(value) return value
Example #16
Source File: widgets.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def _format_value(self, value): if self.is_localized and not self.manual_format: return formats.localize_input(value) elif hasattr(value, 'strftime'): value = datetime_safe.new_datetime(value) return value.strftime(self.format) return value
Example #17
Source File: widgets.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
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)
Example #18
Source File: widgets.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def _format_value(self, value): if self.is_localized and not self.manual_format: return formats.localize_input(value) elif hasattr(value, 'strftime'): value = datetime_safe.new_date(value) return value.strftime(self.format) return value
Example #19
Source File: widgets.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def _format_value(self, value): if self.is_localized: return formats.localize_input(value) return value
Example #20
Source File: _compatibility.py From django-bootstrap-datepicker-plus with Apache License 2.0 | 5 votes |
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)
Example #21
Source File: widgets.py From python with Apache License 2.0 | 5 votes |
def format_value(self, value): if value is not None: # localize_input() returns str on Python 2. return force_text(formats.localize_input(value, self.format or formats.get_format(self.format_key)[0]))
Example #22
Source File: widgets.py From python with Apache License 2.0 | 5 votes |
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)
Example #23
Source File: widgets.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def format_value(self, value): return formats.localize_input(value, self.format or formats.get_format(self.format_key)[0])
Example #24
Source File: widgets.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
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)
Example #25
Source File: widgets.py From bioforum with MIT License | 5 votes |
def format_value(self, value): return formats.localize_input(value, self.format or formats.get_format(self.format_key)[0])
Example #26
Source File: widgets.py From bioforum with MIT License | 5 votes |
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)
Example #27
Source File: widgets.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def _format_value(self, value): return formats.localize_input(value, self.format or formats.get_format(self.format_key)[0])