當前位置: 首頁>>代碼示例>>Python>>正文


Python forms.DecimalField方法代碼示例

本文整理匯總了Python中django.forms.DecimalField方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.DecimalField方法的具體用法?Python forms.DecimalField怎麽用?Python forms.DecimalField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.forms的用法示例。


在下文中一共展示了forms.DecimalField方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: build_default_field

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def build_default_field(self, field, model):
        choices = getattr(field, "choices", None)
        if choices:
            return forms.ChoiceField(
                required=False,
                label=_("Default value"),
                choices=[(None, "-----------")] + list(choices),
            )
        if not (model is Member and field.name == "number"):
            if isinstance(field, models.CharField):
                return forms.CharField(required=False, label=_("Default value"))
            elif isinstance(field, models.DecimalField):
                return forms.DecimalField(
                    required=False,
                    label=_("Default value"),
                    max_digits=field.max_digits,
                    decimal_places=field.decimal_places,
                )
            elif isinstance(field, models.DateField):
                return forms.CharField(required=False, label=_("Other/fixed date")) 
開發者ID:byro,項目名稱:byro,代碼行數:22,代碼來源:registration.py

示例2: to_python

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def to_python(self, value):

        comma_index = 0

        if value:

            # First we check if there is a comma inside the decimal input, and
            # store its position
            try:
                comma_index = value.index(',')
            except ValueError:
                pass

            # If we found a comma inside the input value, we replace it with a
            # regular dot
            if comma_index:
                value = value.replace(',', '.')

        # We finally pass the value (modified or not) to the standard
        # DecimalField
        return super(AllowedCommaDecimalField, self).to_python(value) 
開發者ID:betagouv,項目名稱:mrs,代碼行數:23,代碼來源:forms.py

示例3: test_decimalfield_3

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def test_decimalfield_3(self):
        f = DecimalField(
            max_digits=4, decimal_places=2,
            max_value=decimal.Decimal('1.5'),
            min_value=decimal.Decimal('0.5')
        )
        self.assertWidgetRendersTo(
            f,
            '<input step="0.01" name="f" min="0.5" max="1.5" type="number" id="id_f" required>',
        )
        with self.assertRaisesMessage(ValidationError, "'Ensure this value is less than or equal to 1.5.'"):
            f.clean('1.6')
        with self.assertRaisesMessage(ValidationError, "'Ensure this value is greater than or equal to 0.5.'"):
            f.clean('0.4')
        self.assertEqual(f.clean('1.5'), decimal.Decimal("1.5"))
        self.assertEqual(f.clean('0.5'), decimal.Decimal("0.5"))
        self.assertEqual(f.clean('.5'), decimal.Decimal("0.5"))
        self.assertEqual(f.clean('00.50'), decimal.Decimal("0.50"))
        self.assertEqual(f.max_digits, 4)
        self.assertEqual(f.decimal_places, 2)
        self.assertEqual(f.max_value, decimal.Decimal('1.5'))
        self.assertEqual(f.min_value, decimal.Decimal('0.5')) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:24,代碼來源:test_decimalfield.py

示例4: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def __init__(self, *args, **kwargs):
        fields = (
            forms.CharField(label=_('place')),
            forms.DecimalField(label=_('Latitude')),
            forms.DecimalField(label=_('Longitude')),
        )
        if 'initial' in kwargs:
            kwargs['initial'] = Places(*kwargs['initial'].split(','))
        self.widget = PlacesWidget()
        super(PlacesField, self).__init__(fields, **kwargs) 
開發者ID:oscarmcm,項目名稱:django-places,代碼行數:12,代碼來源:forms.py

示例5: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def __init__(self, event=None, *args, **kwargs):
        super(DonationEntryForm, self).__init__(*args, **kwargs)
        minDonationAmount = (
            event.minimumdonation if event is not None else Decimal('1.00')
        )
        self.fields['amount'] = forms.DecimalField(
            decimal_places=2,
            min_value=minDonationAmount,
            max_value=Decimal('100000'),
            label='Donation Amount (min ${0})'.format(minDonationAmount),
            widget=tracker.widgets.NumberInput(
                attrs={
                    'id': 'iDonationAmount',
                    'min': str(minDonationAmount),
                    'step': '0.01',
                }
            ),
            required=True,
        )
        self.fields['comment'] = forms.CharField(widget=forms.Textarea, required=False)
        self.fields['requestedvisibility'] = forms.ChoiceField(
            initial='CURR',
            choices=models.Donation._meta.get_field('requestedvisibility').choices,
            label='Name Visibility',
        )
        self.fields['requestedalias'] = forms.CharField(
            max_length=32, label='Preferred Alias', required=False
        )
        self.fields['requestedemail'] = forms.EmailField(
            max_length=128, label='Preferred Email', required=False
        )
        self.fields['requestedsolicitemail'] = forms.ChoiceField(
            initial='CURR',
            choices=models.Donation._meta.get_field('requestedsolicitemail').choices,
            label='Charity Email Opt In',
        ) 
開發者ID:GamesDoneQuick,項目名稱:donation-tracker,代碼行數:38,代碼來源:forms.py

示例6: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def __init__(self, n=10, required=True, *args, **kwargs):
        self.n = n
        self.require_one = required
        fields = [
            forms.CharField(required=False, max_length=1000, initial='')
            for _ in range(self.n)
        ]
        fields += [
            forms.DecimalField(required=False, initial=0)
            for _ in range(self.n)
        ]
        super().__init__(fields=fields, require_all_fields=False, required=False, *args, **kwargs)
        self.force_display_required = True 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:15,代碼來源:mc.py

示例7: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def __init__(self, verbose_name=None, name=None, max_digits=None,
                 decimal_places=None, **kwargs):
        self.max_digits, self.decimal_places = max_digits, decimal_places
        super(DecimalField, self).__init__(verbose_name, name, **kwargs) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:6,代碼來源:__init__.py

示例8: check

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def check(self, **kwargs):
        errors = super(DecimalField, self).check(**kwargs)

        digits_errors = self._check_decimal_places()
        digits_errors.extend(self._check_max_digits())
        if not digits_errors:
            errors.extend(self._check_decimal_places_and_max_digits(**kwargs))
        else:
            errors.extend(digits_errors)
        return errors 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:12,代碼來源:__init__.py

示例9: deconstruct

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def deconstruct(self):
        name, path, args, kwargs = super(DecimalField, self).deconstruct()
        if self.max_digits is not None:
            kwargs['max_digits'] = self.max_digits
        if self.decimal_places is not None:
            kwargs['decimal_places'] = self.decimal_places
        return name, path, args, kwargs 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:9,代碼來源:__init__.py

示例10: get_internal_type

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def get_internal_type(self):
        return "DecimalField" 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:4,代碼來源:__init__.py

示例11: get_prep_value

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def get_prep_value(self, value):
        value = super(DecimalField, self).get_prep_value(value)
        return self.to_python(value) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:5,代碼來源:__init__.py

示例12: formfield

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def formfield(self, **kwargs):
        defaults = {
            'max_digits': self.max_digits,
            'decimal_places': self.decimal_places,
            'form_class': forms.DecimalField,
        }
        defaults.update(kwargs)
        return super().formfield(**defaults) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:10,代碼來源:__init__.py

示例13: formfield

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def formfield(self, **kwargs):
        return super().formfield(**{
            'max_digits': self.max_digits,
            'decimal_places': self.decimal_places,
            'form_class': forms.DecimalField,
            **kwargs,
        }) 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:9,代碼來源:__init__.py

示例14: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def __init__(self, required=True, help_text=None, max_value=None, min_value=None,
                 max_digits=None, decimal_places=None, validators=(), *args, **kwargs):
        self.field = forms.DecimalField(
            required=required,
            help_text=help_text,
            max_value=max_value,
            min_value=min_value,
            max_digits=max_digits,
            decimal_places=decimal_places,
            validators=validators,
        )
        super().__init__(*args, **kwargs) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:14,代碼來源:field_block.py

示例15: test_number_field

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import DecimalField [as 別名]
def test_number_field(self):
        data = self.get_form_field_data("number")
        cls = wsf_fields.NumberField()
        field = cls.get_formfield(data)

        self.assertIsInstance(field, forms.DecimalField)
        self.assertIsInstance(field.widget, forms.widgets.NumberInput)
        self.assertEqual(field.label, data["label"])
        self.assertEqual(field.required, data["required"])
        self.assertEqual(field.help_text, data["help_text"])
        self.assertEqual(field.initial, data["default_value"]) 
開發者ID:labd,項目名稱:wagtailstreamforms,代碼行數:13,代碼來源:test_fields.py


注:本文中的django.forms.DecimalField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。