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


Python forms.TextInput方法代码示例

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


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

示例1: __init__

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

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

        if Configuration.false('checkin_require_password'):
            self.fields['password'].required = False

        if Configuration.true('checkin_require_condition'):
            self.fields['condition'].required = True

        if kwargs.get('instance'):
            prod = gsxws.Product('')
            prod.description = self.instance.description

            if prod.is_ios:
                self.fields['password'].label = _('Passcode')

            if not prod.is_ios:
                del(self.fields['imei'])
            if not prod.is_mac:
                del(self.fields['username'])

        if Configuration.true('checkin_password'):
            self.fields['password'].widget = forms.TextInput(attrs={'class': 'span12'}) 
开发者ID:fpsw,项目名称:Servo,代码行数:26,代码来源:checkin.py

示例2: make_entry_field

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TextInput [as 别名]
def make_entry_field(self, fieldsubmission=None):
        self.min_length = 0
        self.max_length = 0

        if self.config['min_length'] and int(self.config['min_length']) > 0:
            self.min_length = int(self.config['min_length'])
        if self.config['max_length'] and int(self.config['max_length']) > 0:
            self.max_length = int(self.config['max_length'])

        c = forms.CharField(required=self.config['required'],
            widget=forms.TextInput(attrs=
                {'size': min(self.config.get('size', 60), int(self.config['max_length'])),
                 'maxlength': int(self.config['max_length'])}),
            label=self.config['label'],
            help_text=self.config['help_text'],
            min_length=self.min_length,
            max_length=self.max_length)

        if fieldsubmission:
            c.initial = fieldsubmission.data['info']

        return c 
开发者ID:sfu-fas,项目名称:coursys,代码行数:24,代码来源:text.py

示例3: get_context

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TextInput [as 别名]
def get_context(self, name, value, attrs):
        context_value = value or [""]
        context = super().get_context(name, context_value, attrs)
        final_attrs = context["widget"]["attrs"]
        id_ = context["widget"]["attrs"].get("id")
        context["widget"]["is_none"] = value is None

        subwidgets = []
        for index, item in enumerate(context["widget"]["value"]):
            widget_attrs = final_attrs.copy()
            if id_:
                widget_attrs["id"] = "{id_}_{index}".format(id_=id_, index=index)
            widget = forms.TextInput()
            widget.is_required = self.is_required
            subwidgets.append(widget.get_context(name, item, widget_attrs)["widget"])

        context["widget"]["subwidgets"] = subwidgets
        return context 
开发者ID:gradam,项目名称:django-better-admin-arrayfield,代码行数:20,代码来源:widgets.py

示例4: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TextInput [as 别名]
def __init__(self, *args, **kwargs):
        org = kwargs.pop("org")
        is_create = kwargs.pop("is_create")

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

        # don't let users change names of existing labels
        if not is_create:
            self.fields["name"].widget = forms.TextInput(attrs={"readonly": "readonly"})

        self.fields["groups"].queryset = Group.get_all(org).order_by("name")

        self.fields["field_test"] = FieldTestField(
            org=org,
            label=_("Field criteria"),
            required=False,
            help_text=_("Match messages where contact field value is equal to any of these values (comma separated)"),
        ) 
开发者ID:rapidpro,项目名称:casepro,代码行数:20,代码来源:forms.py

示例5: __init__

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

        self.fields['in_book'].initial = is_in_book
        self.fields['in_book'].widget.attrs.update({
            'data-bind': "checked: inBook"})
        self.fields['amount'].widget.attrs.update({
            'class': "form-control input-lg text-center",
            'data-bind': "textInput: productAmount"})
        self.fields['discount'].widget.attrs['data-bind'] = "checked: hasTejoDiscount, cli"
        self.fields['support'].localize = True
        self.fields['support'].widget = forms.TextInput(attrs={
            'class': "form-control pull-right same-as-body",
            'style': "width: 5em; text-align: right; padding-right: calc(1em - 1px)",
            'pattern': "[0-9]{1,4},[0-9]{2}",
            'data-bind': "textInput: supportInput"}) 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:21,代码来源:forms.py

示例6: __init__

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

        # 只修改widget
        self.fields['username'].widget = widgets.TextInput(
            attrs={
                'placeholder': 'Username',
                'class': 'form-control',
                'style': 'margin-bottom: 10px'
            })
        self.fields['email'].widget = widgets.EmailInput(
            attrs={
                'placeholder': 'Email',
                'class': 'form-control'
            })
        self.fields['password1'].widget = widgets.PasswordInput(
            attrs={
                'placeholder': 'New password',
                'class': 'form-control'
            })
        self.fields['password2'].widget = widgets.PasswordInput(
            attrs={
                'placeholder': 'Repeat password',
                'class': 'form-control'
            }) 
开发者ID:enjoy-binbin,项目名称:Django-blog,代码行数:27,代码来源:forms.py

示例7: render

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TextInput [as 别名]
def render(self, name, value, attrs=None, renderer=None):
        text = super(TextInput, self).render(name, value, attrs)
        return mark_safe(text + format_html(
            '''\
<a href="#" onclick="return false;" class="button" id="id_{0}_regen">Regenerate</a>
<script type="text/javascript">
django.jQuery(document).ready(function ($) {{
    $('#id_{0}_regen').click(function () {{
        var length = 100,
            charset = "abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`~!@#$%^&*()_+-=|[]{{}};:,<>./?",
            key = "";
        for (var i = 0, n = charset.length; i < length; ++i) {{
            key += charset.charAt(Math.floor(Math.random() * n));
        }}
        $('#id_{0}').val(key);
    }});
}});
</script>
''', name)) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:21,代码来源:runtime.py

示例8: __init__

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

        if key_type == 'rich-text':
            self.fields['value'].widget = SummernoteWidget()
        elif key_type == 'boolean':
            self.fields['value'].widget = forms.CheckboxInput()
        elif key_type == 'integer':
            self.fields['value'].widget = forms.TextInput(attrs={'type': 'number'})
        elif key_type == 'file' or key_type == 'journalthumb':
            self.fields['value'].widget = forms.FileInput()
        elif key_type == 'text':
            self.fields['value'].widget = forms.Textarea()
        else:
            self.fields['value'].widget.attrs['size'] = '100%'

        self.fields['value'].initial = value
        self.fields['value'].required = False 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:22,代码来源:forms.py

示例9: test_widget_media

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TextInput [as 别名]
def test_widget_media(self):
        class CalendarWidget(forms.TextInput):
            @property
            def media(self):
                return forms.Media(
                    css={'all': ('pretty.css',)},
                    js=('animations.js', 'actions.js')
                )

        class CalenderBlock(blocks.FieldBlock):
            def __init__(self, required=True, help_text=None, max_length=None, min_length=None, **kwargs):
                # Set widget to CalenderWidget
                self.field = forms.CharField(
                    required=required,
                    help_text=help_text,
                    max_length=max_length,
                    min_length=min_length,
                    widget=CalendarWidget(),
                )
                super(blocks.FieldBlock, self).__init__(**kwargs)

        block = CalenderBlock()
        self.assertIn('pretty.css', ''.join(block.all_media().render_css()))
        self.assertIn('animations.js', ''.join(block.all_media().render_js())) 
开发者ID:wagtail,项目名称:wagtail,代码行数:26,代码来源:test_blocks.py

示例10: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TextInput [as 别名]
def __init__(self, *args, **kwargs):
		"""
			Initialize the form. A keyword argument 'placeholder' may be
			given.

			This can be customized to specify additional parameters if it
			needs to.
		"""
		if 'placeholder' in kwargs:
			self.placeholder = kwargs.pop('placeholder')
			# must be called after 'placeholder' is popped from kwargs
			super(SearchForm, self).__init__(*args, **kwargs)
			self.fields['search'].widget = forms.TextInput(attrs={'placeholder': self.placeholder, 'class': 'form-control', 'type': 'text', 'name': 'search'})
		else:
			super(SearchForm, self).__init__(*args, **kwargs)
			self.fields['search'].widget = forms.TextInput(attrs={'class': 'form-control', 'type': 'text', 'name': 'search'}) 
开发者ID:Murali-group,项目名称:GraphSpace,代码行数:18,代码来源:forms.py

示例11: identification_field_factory

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TextInput [as 别名]
def identification_field_factory(label, error_required):
    """
    A simple identification field factory which enable you to set the label.

    :param label:
        String containing the label for this field.

    :param error_required:
        String containing the error message if the field is left empty.

    """
    return forms.CharField(
        label=label,
        widget=forms.TextInput(attrs=attrs_dict),
        max_length=75,
        error_messages={"required": error_required},
    ) 
开发者ID:django-userena-ce,项目名称:django-userena-ce,代码行数:19,代码来源:forms.py

示例12: render

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TextInput [as 别名]
def render(self, name, value, attrs=None):
        if not self._isiterable(value):
            value = [value]

        if len(value) <= 1:
            # delegate to main widget (Select, etc...) if not multiple values
            value = value[0] if value else ''
            return super(BaseCSVWidget, self).render(name, value, attrs)

        # if we have multiple values, we need to force render as a text input
        # (otherwise, the additional values are lost)
        surrogate = forms.TextInput()
        value = [force_text(format_value(surrogate, v)) for v in value]
        value = ','.join(list(value))

        return surrogate.render(name, value, attrs) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:18,代码来源:widgets.py

示例13: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TextInput [as 别名]
def __init__(self, *args, **kwargs):
        kwargs.setdefault('label_suffix', '')
        super(PoliticianForm, self).__init__(*args, **kwargs)
        for field_name, field in self.fields.items():
            if isinstance(field.widget, forms.TextInput) or isinstance(field.widget, forms.Select) or isinstance(field.widget, forms.EmailInput):
                field.widget.attrs.update({
                    'class': 'form-control'
                })
            if field_name == 'party':
                field.choices = [('', '---------')]
                field.choices += [
                    (p.id, p.name)
                    for p
                    in Party.objects.order_by('name')
                ]

            if isinstance(field.widget, forms.Textarea):
                field.widget.attrs.update({
                    'class': 'form-control',
                    'rows': 2,
                }) 
开发者ID:freedomvote,项目名称:freedomvote,代码行数:23,代码来源:forms.py

示例14: test_multi_media

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TextInput [as 别名]
def test_multi_media(self):
        ###############################################################
        # Multi-media handling for CSS
        ###############################################################

        # A widget can define CSS media for multiple output media types
        class MultimediaWidget(TextInput):
            class Media:
                css = {
                    'screen, print': ('/file1', '/file2'),
                    'screen': ('/file3',),
                    'print': ('/file4',)
                }
                js = ('/path/to/js1', '/path/to/js4')

        multimedia = MultimediaWidget()
        self.assertEqual(
            str(multimedia.media),
            """<link href="/file4" type="text/css" media="print" rel="stylesheet">
<link href="/file3" type="text/css" media="screen" rel="stylesheet">
<link href="/file1" type="text/css" media="screen, print" rel="stylesheet">
<link href="/file2" type="text/css" media="screen, print" rel="stylesheet">
<script type="text/javascript" src="/path/to/js1"></script>
<script type="text/javascript" src="/path/to/js4"></script>"""
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:27,代码来源:test_media.py

示例15: test_formfield_overrides_widget_instances

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import TextInput [as 别名]
def test_formfield_overrides_widget_instances(self):
        """
        Widget instances in formfield_overrides are not shared between
        different fields. (#19423)
        """
        class BandAdmin(admin.ModelAdmin):
            formfield_overrides = {
                CharField: {'widget': forms.TextInput(attrs={'size': '10'})}
            }
        ma = BandAdmin(Band, admin.site)
        f1 = ma.formfield_for_dbfield(Band._meta.get_field('name'), request=None)
        f2 = ma.formfield_for_dbfield(Band._meta.get_field('style'), request=None)
        self.assertNotEqual(f1.widget, f2.widget)
        self.assertEqual(f1.widget.attrs['maxlength'], '100')
        self.assertEqual(f2.widget.attrs['maxlength'], '20')
        self.assertEqual(f2.widget.attrs['size'], '10') 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:tests.py


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