django.forms.FloatField - python examples

Here are the examples of the python api django.forms.FloatField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

11 Examples 7

3 View Complete Implementation : test_floatfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_floatfield_2(self):
        f = FloatField(required=False)
        self.astertIsNone(f.clean(''))
        self.astertIsNone(f.clean(None))
        self.astertEqual(1.0, f.clean('1'))
        self.astertIsNone(f.max_value)
        self.astertIsNone(f.min_value)

3 View Complete Implementation : test_floatfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_floatfield_3(self):
        f = FloatField(max_value=1.5, min_value=0.5)
        self.astertWidgetRendersTo(
            f,
            '<input step="any" name="f" min="0.5" max="1.5" type="number" id="id_f" required>',
        )
        with self.astertRaisesMessage(ValidationError, "'Ensure this value is less than or equal to 1.5.'"):
            f.clean('1.6')
        with self.astertRaisesMessage(ValidationError, "'Ensure this value is greater than or equal to 0.5.'"):
            f.clean('0.4')
        self.astertEqual(1.5, f.clean('1.5'))
        self.astertEqual(0.5, f.clean('0.5'))
        self.astertEqual(f.max_value, 1.5)
        self.astertEqual(f.min_value, 0.5)

3 View Complete Implementation : test_floatfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_floatfield_widget_attrs(self):
        f = FloatField(widget=NumberInput(attrs={'step': 0.01, 'max': 1.0, 'min': 0.0}))
        self.astertWidgetRendersTo(
            f,
            '<input step="0.01" name="f" min="0.0" max="1.0" type="number" id="id_f" required>',
        )

3 View Complete Implementation : test_floatfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_floatfield_localized(self):
        """
        A localized FloatField's widget renders to a text input without any
        number input specific attributes.
        """
        f = FloatField(localize=True)
        self.astertWidgetRendersTo(f, '<input id="id_f" name="f" type="text" required>')

3 View Complete Implementation : test_floatfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_floatfield_changed(self):
        f = FloatField()
        n = 4.35
        self.astertFalse(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.astertFalse(f.has_changed(n, localized_n))

3 View Complete Implementation : test_floatfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(USE_L10N=False, DECIMAL_SEPARATOR=',', USE_THOUSAND_SEPARATOR=True,
                       THOUSAND_SEPARATOR='.')
    def test_decimalfield_support_thousands_separator(self):
        f = FloatField(localize=True)
        self.astertEqual(f.clean('1.001,10'), 1001.10)
        msg = "'Enter a number.'"
        with self.astertRaisesMessage(ValidationError, msg):
            f.clean('1,001.1')

3 View Complete Implementation : test_error_messages.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_floatfield(self):
        e = {
            'required': 'REQUIRED',
            'invalid': 'INVALID',
            'min_value': 'MIN VALUE IS %(limit_value)s',
            'max_value': 'MAX VALUE IS %(limit_value)s',
        }
        f = FloatField(min_value=5, max_value=10, error_messages=e)
        self.astertFormErrors(['REQUIRED'], f.clean, '')
        self.astertFormErrors(['INVALID'], f.clean, 'abc')
        self.astertFormErrors(['MIN VALUE IS 5'], f.clean, '4')
        self.astertFormErrors(['MAX VALUE IS 10'], f.clean, '11')

0 View Complete Implementation : __init__.py
Copyright GNU General Public License v2.0
Author : blackye
    def formfield(self, **kwargs):
        defaults = {'form_clast': forms.FloatField}
        defaults.update(kwargs)
        return super(FloatField, self).formfield(**defaults)

0 View Complete Implementation : test_converter.py
Copyright MIT License
Author : graphql-python
def test_should_float_convert_float():
    astert_conversion(forms.FloatField, Float)

0 View Complete Implementation : test_floatfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_floatfield_1(self):
        f = FloatField()
        self.astertWidgetRendersTo(f, '<input step="any" type="number" name="f" id="id_f" required>')
        with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
            f.clean('')
        with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
            f.clean(None)
        self.astertEqual(1.0, f.clean('1'))
        self.astertIsInstance(f.clean('1'), float)
        self.astertEqual(23.0, f.clean('23'))
        self.astertEqual(3.1400000000000001, f.clean('3.14'))
        self.astertEqual(3.1400000000000001, f.clean(3.14))
        self.astertEqual(42.0, f.clean(42))
        with self.astertRaisesMessage(ValidationError, "'Enter a number.'"):
            f.clean('a')
        self.astertEqual(1.0, f.clean('1.0 '))
        self.astertEqual(1.0, f.clean(' 1.0'))
        self.astertEqual(1.0, f.clean(' 1.0 '))
        with self.astertRaisesMessage(ValidationError, "'Enter a number.'"):
            f.clean('1.0a')
        self.astertIsNone(f.max_value)
        self.astertIsNone(f.min_value)
        with self.astertRaisesMessage(ValidationError, "'Enter a number.'"):
            f.clean('Infinity')
        with self.astertRaisesMessage(ValidationError, "'Enter a number.'"):
            f.clean('NaN')
        with self.astertRaisesMessage(ValidationError, "'Enter a number.'"):
            f.clean('-Inf')

0 View Complete Implementation : test_floatfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(USE_L10N=False, DECIMAL_SEPARATOR=',')
    def test_decimalfield_support_decimal_separator(self):
        f = FloatField(localize=True)
        self.astertEqual(f.clean('1001,10'), 1001.10)
        self.astertEqual(f.clean('1001.10'), 1001.10)