当前位置: 首页>>代码示例>>Python>>正文


Python forms.NumberInput方法代码示例

本文整理汇总了Python中django.forms.NumberInput方法的典型用法代码示例。如果您正苦于以下问题:Python forms.NumberInput方法的具体用法?Python forms.NumberInput怎么用?Python forms.NumberInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms的用法示例。


在下文中一共展示了forms.NumberInput方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import NumberInput [as 别名]
def __init__(self, *args, **kwargs):
        name = kwargs.pop('name')
        super().__init__(*args, **kwargs)

        self.fields[name] = forms.FloatField(label='', required=False,
            widget=forms.NumberInput(attrs={'placeholder': _('Value')})) 
开发者ID:lukasvinclav,项目名称:django-admin-numeric-filter,代码行数:8,代码来源:forms.py

示例2: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import NumberInput [as 别名]
def __init__(self, *args, **kwargs):
        election = kwargs.pop('election')
        post = kwargs.pop('post')
        super(AddCandidacyPickPartyForm, self).__init__(*args, **kwargs)
        party_set = PartySet.objects.get(postextra__slug=post)

        self.fields['party'] = \
            forms.ChoiceField(
                label=_("Party in {election}").format(
                    election=election.name,
                ),
                choices=party_set.party_choices(),
                required=False,
                widget=forms.Select(
                    attrs={
                        'class': 'party-select party-select-' + election.slug
                    }
                ),
            )
        if election.party_lists_in_use:
            # Then add a field to enter the position on the party list
            # as an integer:
            self.fields['party_list_position'] = forms.IntegerField(
                label=_("Position in party list ('1' for first, '2' for second, etc.)"),
                min_value=1,
                required=False,
                widget=forms.NumberInput(
                    attrs={
                        'class': 'party-position party-position-' + election.slug
                    }
                )
            ) 
开发者ID:mysociety,项目名称:yournextrepresentative,代码行数:34,代码来源:forms.py

示例3: test_floatfield_widget_attrs

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import NumberInput [as 别名]
def test_floatfield_widget_attrs(self):
        f = FloatField(widget=NumberInput(attrs={'step': 0.01, 'max': 1.0, 'min': 0.0}))
        self.assertWidgetRendersTo(
            f,
            '<input step="0.01" name="f" min="0.0" max="1.0" type="number" id="id_f" required>',
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_floatfield.py

示例4: test_decimalfield_widget_attrs

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import NumberInput [as 别名]
def test_decimalfield_widget_attrs(self):
        f = DecimalField(max_digits=6, decimal_places=2)
        self.assertEqual(f.widget_attrs(Widget()), {})
        self.assertEqual(f.widget_attrs(NumberInput()), {'step': '0.01'})
        f = DecimalField(max_digits=10, decimal_places=0)
        self.assertEqual(f.widget_attrs(NumberInput()), {'step': '1'})
        f = DecimalField(max_digits=19, decimal_places=19)
        self.assertEqual(f.widget_attrs(NumberInput()), {'step': '1e-19'})
        f = DecimalField(max_digits=20)
        self.assertEqual(f.widget_attrs(NumberInput()), {'step': 'any'})
        f = DecimalField(max_digits=6, widget=NumberInput(attrs={'step': '0.01'}))
        self.assertWidgetRendersTo(f, '<input step="0.01" name="f" type="number" id="id_f" required>') 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:test_decimalfield.py

示例5: prepare_number

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import NumberInput [as 别名]
def prepare_number(self, field):
        field_attrs = field.build_field_attrs()
        widget_attrs = field.build_widget_attrs()

        field_attrs.update({
            'widget': forms.NumberInput(attrs=widget_attrs)
        })
        return forms.IntegerField(**field_attrs) 
开发者ID:mishbahr,项目名称:djangocms-forms,代码行数:10,代码来源:forms.py

示例6: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import NumberInput [as 别名]
def __init__(self, transaction: Transaction, *args, **kwargs):
        # For testing via anchor-validator.herokuapp.com
        test_value = kwargs.pop("test_value", None)
        if not test_value:
            test_value = (
                "103" if transaction.kind == Transaction.KIND.deposit else "100"
            )

        super().__init__(*args, **kwargs)

        self.transaction = transaction
        self.asset = transaction.asset
        self.decimal_places = self.asset.significant_decimals
        if transaction.kind == Transaction.KIND.deposit:
            self.min_amount = round(self.asset.deposit_min_amount, self.decimal_places)
            self.max_amount = round(self.asset.deposit_max_amount, self.decimal_places)
            self.min_default = Asset._meta.get_field("deposit_min_amount").default
            self.max_default = Asset._meta.get_field("deposit_max_amount").default
        else:
            self.min_amount = round(
                self.asset.withdrawal_min_amount, self.decimal_places
            )
            self.max_amount = round(
                self.asset.withdrawal_max_amount, self.decimal_places
            )
            self.min_default = Asset._meta.get_field("withdrawal_min_amount").default
            self.max_default = Asset._meta.get_field("withdrawal_max_amount").default

        # Re-initialize the 'amount' field now that we have all the parameters necessary
        self.fields["amount"].__init__(
            widget=forms.NumberInput(
                attrs={
                    "class": "input",
                    "inputmode": "decimal",
                    "symbol": self.asset.symbol,
                    "test-value": test_value,
                }
            ),
            min_value=self.min_amount,
            max_value=self.max_amount,
            decimal_places=self.decimal_places,
            label=_("Amount"),
            localize=True,
        )

        limit_str = ""
        if self.min_amount > self.min_default and self.max_amount < self.max_default:
            limit_str = f"({intcomma(self.min_amount)} - {intcomma(self.max_amount)})"
        elif self.min_amount > self.min_default:
            limit_str = _("(minimum: %s)") % intcomma(self.min_amount)
        elif self.max_amount < self.max_default:
            limit_str = _("(maximum: %s)") % intcomma(self.max_amount)

        if limit_str:
            self.fields["amount"].label += " " + limit_str 
开发者ID:stellar,项目名称:django-polaris,代码行数:57,代码来源:forms.py


注:本文中的django.forms.NumberInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。