removed localize for FloatField

This commit is contained in:
kiyoqoko 2016-07-05 09:33:54 +02:00 committed by bryst
parent dcf7f16abd
commit cd8ac6cb1a
2 changed files with 7 additions and 23 deletions

View File

@ -276,7 +276,7 @@ class Field(object):
def __init__(self, read_only=False, write_only=False, def __init__(self, read_only=False, write_only=False,
required=None, default=empty, initial=empty, source=None, required=None, default=empty, initial=empty, source=None,
label=None, help_text=None, style=None, label=None, help_text=None, style=None,
error_messages=None, validators=None, allow_null=False, localize=False): error_messages=None, validators=None, allow_null=False):
self._creation_counter = Field._creation_counter self._creation_counter = Field._creation_counter
Field._creation_counter += 1 Field._creation_counter += 1
@ -300,7 +300,6 @@ class Field(object):
self.help_text = help_text self.help_text = help_text
self.style = {} if style is None else style self.style = {} if style is None else style
self.allow_null = allow_null self.allow_null = allow_null
self.localize = localize
if self.default_empty_html is not empty: if self.default_empty_html is not empty:
if default is not empty: if default is not empty:
@ -874,8 +873,6 @@ class FloatField(Field):
def to_internal_value(self, data): def to_internal_value(self, data):
if self.localize:
data = sanitize_separators(data)
if isinstance(data, six.text_type) and len(data) > self.MAX_STRING_LENGTH: if isinstance(data, six.text_type) and len(data) > self.MAX_STRING_LENGTH:
self.fail('max_string_length') self.fail('max_string_length')
@ -885,10 +882,7 @@ class FloatField(Field):
self.fail('invalid') self.fail('invalid')
def to_representation(self, value): def to_representation(self, value):
value = float(value) return float(value)
if self.localize:
value = localize_input(value)
return value
class DecimalField(Field): class DecimalField(Field):
@ -903,9 +897,11 @@ class DecimalField(Field):
} }
MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs. MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs.
def __init__(self, max_digits, decimal_places, coerce_to_string=None, max_value=None, min_value=None, **kwargs): def __init__(self, max_digits, decimal_places, coerce_to_string=None, max_value=None, min_value=None,
localize=False, **kwargs):
self.max_digits = max_digits self.max_digits = max_digits
self.decimal_places = decimal_places self.decimal_places = decimal_places
self.localize = localize
if coerce_to_string is not None: if coerce_to_string is not None:
self.coerce_to_string = coerce_to_string self.coerce_to_string = coerce_to_string

View File

@ -896,29 +896,17 @@ class TestNoStringCoercionDecimalField(FieldValues):
class TestLocalizedDecimalField(TestCase): class TestLocalizedDecimalField(TestCase):
@override_settings(USE_L10N=True, LANGUAGE_CODE='pl', LANGUAGES=(('pl', 'Polish'),)) @override_settings(USE_L10N=True, LANGUAGE_CODE='pl')
def test_to_internal_value(self): def test_to_internal_value(self):
field = serializers.DecimalField(max_digits=2, decimal_places=1, localize=True) field = serializers.DecimalField(max_digits=2, decimal_places=1, localize=True)
self.assertEqual(field.to_internal_value('1,1'), Decimal('1.1')) self.assertEqual(field.to_internal_value('1,1'), Decimal('1.1'))
@override_settings(USE_L10N=True, LANGUAGE_CODE='pl', LANGUAGES=(('pl', 'Polish'),)) @override_settings(USE_L10N=True, LANGUAGE_CODE='pl')
def test_to_representation(self): def test_to_representation(self):
field = serializers.DecimalField(max_digits=2, decimal_places=1, localize=True) field = serializers.DecimalField(max_digits=2, decimal_places=1, localize=True)
self.assertEqual(field.to_representation(Decimal('1.1')), '1,1') self.assertEqual(field.to_representation(Decimal('1.1')), '1,1')
class TestLocalizedFloatField(TestCase):
@override_settings(USE_L10N=True, LANGUAGE_CODE='pl', LANGUAGES=(('pl', 'Polish'),))
def test_to_internal_value(self):
field = serializers.FloatField(localize=True)
self.assertEqual(field.to_internal_value('1,1'), 1.1)
@override_settings(USE_L10N=True, LANGUAGE_CODE='pl', LANGUAGES=(('pl', 'Polish'),))
def test_to_representation(self):
field = serializers.FloatField(localize=True)
self.assertEqual(field.to_representation(1.1), '1,1')
class TestNoDecimalPlaces(FieldValues): class TestNoDecimalPlaces(FieldValues):
valid_inputs = { valid_inputs = {
'0.12345': Decimal('0.12345'), '0.12345': Decimal('0.12345'),