Python django.forms.widgets 模块,TextInput() 实例源码

我们从Python开源项目中,提取了以下46个代码示例,用于说明如何使用django.forms.widgets.TextInput()

项目:mos-horizon    作者:Mirantis    | 项目源码 | 文件源码
def test_edit_attachments_auto_device_name(self):
        volume = self.cinder_volumes.first()
        servers = [s for s in self.servers.list()
                   if s.tenant_id == self.request.user.tenant_id]
        volume.attachments = [{'id': volume.id,
                               'volume_id': volume.id,
                               'volume_name': volume.name,
                               'instance': servers[0],
                               'device': '',
                               'server_id': servers[0].id}]

        cinder.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)
        api.nova.server_list(IsA(http.HttpRequest)).AndReturn([servers, False])
        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:volumes:attach',
                      args=[volume.id])
        res = self.client.get(url)
        form = res.context['form']
        self.assertIsInstance(form.fields['device'].widget,
                              widgets.TextInput)
        self.assertFalse(form.fields['device'].required)
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def __init__(self, attrs=None):
        color_widget = widgets.TextInput(attrs={
            'type': 'color',
            'class': 'colorfield-preview input-small',
        })
        input_widget = widgets.TextInput(attrs={
            'max_length': 7,
            'placeholder': 'hex color',
            'class': 'colorfield-hex input-small',
            'pattern': '#?([0-9a-fA-F]{6}|[0-9a-fA-F]{3})',
        })
        opacity_widget = widgets.TextInput(attrs={
            'type': 'number',
            'placeholder': 'opacity',
            'class': 'colorfield-opacity input-mini',
            'step': '0.05',
            'min': 0,
            'max': 1,
        })
        _widgets = (color_widget, input_widget, opacity_widget)
        super().__init__(_widgets, attrs)
项目:maas    作者:maas    | 项目源码 | 文件源码
def test_DictCharWidget_renders_fieldset_with_label_and_field_names(self):
        names = [factory.make_string(), factory.make_string()]
        initials = []
        labels = [factory.make_string(), factory.make_string()]
        values = [factory.make_string(), factory.make_string()]
        widget = DictCharWidget(
            [widgets.TextInput, widgets.TextInput, widgets.CheckboxInput],
            names, initials, labels, skip_check=True)
        name = factory.make_string()
        html_widget = fromstring(
            '<root>' + widget.render(name, values) + '</root>')
        widget_names = XPath('fieldset/input/@name')(html_widget)
        widget_labels = XPath('fieldset/label/text()')(html_widget)
        widget_values = XPath('fieldset/input/@value')(html_widget)
        expected_names = [
            "%s_%s" % (name, widget_name) for widget_name in names]
        self.assertEqual(
            [expected_names, labels, values],
            [widget_names, widget_labels, widget_values])
项目:maas    作者:maas    | 项目源码 | 文件源码
def test_DictCharWidget_value_from_datadict_values_from_data(self):
        # 'value_from_datadict' extracts the values corresponding to the
        # field as a dictionary.
        names = [factory.make_string(), factory.make_string()]
        initials = []
        labels = [factory.make_string(), factory.make_string()]
        name = factory.make_string()
        field_1_value = factory.make_string()
        field_2_value = factory.make_string()
        # Create a query string with the field2 before the field1 and another
        # (unknown) value.
        data = QueryDict(
            '%s_%s=%s&%s_%s=%s&%s=%s' % (
                name, names[1], field_2_value,
                name, names[0], field_1_value,
                factory.make_string(), factory.make_string())
            )
        widget = DictCharWidget(
            [widgets.TextInput, widgets.TextInput], names, initials, labels)
        self.assertEqual(
            {names[0]: field_1_value, names[1]: field_2_value},
            widget.value_from_datadict(data, None, name))
项目:maas    作者:maas    | 项目源码 | 文件源码
def test_DictCharWidget_renders_with_empty_string_as_input_data(self):
        names = [factory.make_string(), factory.make_string()]
        initials = []
        labels = [factory.make_string(), factory.make_string()]
        widget = DictCharWidget(
            [widgets.TextInput, widgets.TextInput, widgets.CheckboxInput],
            names, initials, labels, skip_check=True)
        name = factory.make_string()
        html_widget = fromstring(
            '<root>' + widget.render(name, '') + '</root>')
        widget_names = XPath('fieldset/input/@name')(html_widget)
        widget_labels = XPath('fieldset/label/text()')(html_widget)
        expected_names = [
            "%s_%s" % (name, widget_name) for widget_name in names]
        self.assertEqual(
            [expected_names, labels],
            [widget_names, widget_labels])
项目:mos-horizon    作者:Mirantis    | 项目源码 | 文件源码
def test_edit_attachments(self):
        volume = self.cinder_volumes.first()
        servers = [s for s in self.servers.list()
                   if s.tenant_id == self.request.user.tenant_id]
        volume.attachments = [{'id': volume.id,
                               'volume_id': volume.id,
                               'volume_name': volume.name,
                               'instance': servers[0],
                               'device': '/dev/vdb',
                               'server_id': servers[0].id}]

        cinder.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)
        api.nova.server_list(IsA(http.HttpRequest)).AndReturn([servers, False])
        self.mox.ReplayAll()

        url = reverse('horizon:project:volumes:volumes:attach',
                      args=[volume.id])
        res = self.client.get(url)
        msg = 'Volume %s on instance %s' % (volume.name, servers[0].name)
        self.assertContains(res, msg)
        # Asserting length of 2 accounts for the one instance option,
        # and the one 'Choose Instance' option.
        form = res.context['form']
        self.assertEqual(len(form.fields['instance']._choices),
                         1)
        self.assertEqual(res.status_code, 200)
        self.assertIsInstance(form.fields['device'].widget,
                              widgets.TextInput)
        self.assertFalse(form.fields['device'].required)
项目:mos-horizon    作者:Mirantis    | 项目源码 | 文件源码
def test_launch_form_instance_device_name_showed(self):
        self._test_launch_form_instance_show_device_name(
            u'vda', widgets.TextInput, {
                'name': 'device_name', 'value': 'vda',
                'attrs': {'id': 'id_device_name'}}
        )
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:django    作者:alexsukhrin    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:steemprojects.com    作者:noisy    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(PackageForm, self).__init__(*args, **kwargs)
        self.fields['category'].help_text = package_help_text()
        self.fields['repo_url'].widget = TextInput(attrs={
            'placeholder': 'ex: https://github.com/steemit/steem'
        })
        self.fields['description'].widget = Textarea(attrs={
            "placeholder": "Write few sentences about this projects. What problem does it solve? Who is it for?"
        })
        self.fields['contact_url'].widget = TextInput(attrs={
            "placeholder": "Link to channel on steemit.chat, discord, slack, etc"
        })
项目:djragondrop    作者:petroleyum    | 项目源码 | 文件源码
def form_class_from_model(self):
        if self.model_name in self.model_form_fields:
            Form = modelform_factory(self.model, fields=self.model_form_fields[self.model_name], widgets={'user': widgets.TextInput})
        else:
            Form = modelform_factory(self.model, exclude=self.excluded_fields, widgets={'user': widgets.TextInput})
        return Form
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def __init__(self, attrs=None):
        color_widget = widgets.TextInput(attrs={
            'type': 'color',
            'class': 'colorfield-preview input-small',
        })
        input_widget = widgets.TextInput(attrs={
            'max_length': 7,
            'placeholder': 'hex color',
            'class': 'colorfield-hex input-small',
            'pattern': '#?([0-9a-fA-F]{6}|[0-9a-fA-F]{3})',
        })
        _widgets = (color_widget, input_widget)
        super().__init__(_widgets, attrs)
项目:Gypsy    作者:benticarlos    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:wanblog    作者:wanzifa    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:tabmaster    作者:NicolasMinghetti    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:django-verified-email-field    作者:misli    | 项目源码 | 文件源码
def __init__(self, send_label, fieldsetup_id, email_attrs, code_attrs):
        self.send_label = send_label
        self.fieldsetup_id = fieldsetup_id
        widgets = (EmailInput(attrs=email_attrs), TextInput(attrs=code_attrs))
        super(VerifiedEmailWidget, self).__init__(widgets)
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:hydra    作者:Our-Revolution    | 项目源码 | 文件源码
def __init__(self, attrs=None):
        _widgets = (
            widgets.TextInput(attrs=attrs),
            widgets.Select(attrs=attrs, choices=Event.DURATION_MULTIPLIER),
        )
        super(UnitsAndDurationWidget, self).__init__(_widgets, attrs)
项目:ims    作者:ims-team    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:django-open-lecture    作者:DmLitov4    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:travlr    作者:gauravkulkarni96    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:DjangoBlog    作者:liangliangyy    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(LoginForm, self).__init__(*args, **kwargs)
        self.fields['username'].widget = widgets.TextInput(attrs={'placeholder': "username", "class": "form-control"})
        self.fields['password'].widget = widgets.PasswordInput(
            attrs={'placeholder': "password", "class": "form-control"})
项目:DjangoBlog    作者:liangliangyy    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(RegisterForm, self).__init__(*args, **kwargs)

        self.fields['username'].widget = widgets.TextInput(attrs={'placeholder': "username", "class": "form-control"})
        self.fields['email'].widget = widgets.EmailInput(attrs={'placeholder': "email", "class": "form-control"})
        self.fields['password1'].widget = widgets.PasswordInput(
            attrs={'placeholder': "password", "class": "form-control"})
        self.fields['password2'].widget = widgets.PasswordInput(
            attrs={'placeholder': "repeat password", "class": "form-control"})
项目:logo-gen    作者:jellene4eva    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:gmail_scanner    作者:brandonhub    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:CSCE482-WordcloudPlus    作者:ggaytan00    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:tissuelab    作者:VirtualPlants    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:producthunt    作者:davidgengler    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:django-rtc    作者:scifiswapnil    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:geekpoint    作者:Lujinghu    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:LatinSounds_AppEnviaMail    作者:G3ek-aR    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:maas    作者:maas    | 项目源码 | 文件源码
def test_DictCharWidget_id_for_label_uses_first_fields_name(self):
        names = [factory.make_string()]
        initials = []
        labels = [factory.make_string()]
        widget = DictCharWidget(
            [widgets.TextInput, widgets.TextInput], names, initials, labels)
        self.assertEqual(
            ' _%s' % names[0],
            widget.id_for_label(' '))
项目:maas    作者:maas    | 项目源码 | 文件源码
def test_DictCharWidget_renders_with_initial_when_no_value(self):
        """Widgets should use initial value if rendered without value."""
        names = [factory.make_name()]
        initials = [factory.make_name()]
        labels = [factory.make_name()]
        mock_widget = Mock()
        mock_widget.configure_mock(**{"render.return_value": ""})
        widget = DictCharWidget([mock_widget, widgets.TextInput],
                                names, initials, labels, skip_check=True)
        widget.render('foo', [])

        self.assertThat(
            mock_widget.render, MockCalledOnceWith(ANY, initials[0], ANY))
项目:DjangoZeroToHero    作者:RayParra    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:Roboism    作者:markroxor    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def as_text(self, attrs=None, **kwargs):
        """
        Returns a string of HTML for representing this as an <input type="text">.
        """
        return self.as_widget(TextInput(), attrs, **kwargs)
项目:adhocracy4    作者:liqd    | 项目源码 | 文件源码
def render(self, name, value, attrs=None):
        html_id = attrs and attrs.get('id', name) or name
        has_image_set = self.is_initial(value)
        is_required = self.is_required

        file_placeholder = ugettext('Select a picture from your local folder.')
        file_input = super().render(name, None, {
            'id': html_id,
            'class': 'form-control form-control-file'
        })

        if has_image_set:
            file_name = basename(value.name)
            file_url = conditional_escape(value.url)
        else:
            file_name = ""
            file_url = ""

        text_input = widgets.TextInput().render('__noname__', file_name, {
            'class': 'form-control form-control-file-dummy',
            'placeholder': file_placeholder,
            'tabindex': '-1',
            'id': 'text-{}'.format(html_id)
        })

        checkbox_id = self.clear_checkbox_id(name)
        checkbox_name = self.clear_checkbox_name(name)
        checkbox_input = widgets.CheckboxInput().render(checkbox_name, False, {
            'id': checkbox_id,
            'class': 'clear-image',
            'data-upload-clear': html_id,
        })

        context = {
            'id': html_id,
            'has_image_set': has_image_set,
            'is_required': is_required,
            'file_url': file_url,
            'file_input': file_input,
            'file_id': html_id + '-file',
            'text_input': text_input,
            'checkbox_input': checkbox_input,
            'checkbox_id': checkbox_id
        }

        return loader.render_to_string(
            'a4images/image_upload_widget.html',
            context
        )
项目:a4-opin    作者:liqd    | 项目源码 | 文件源码
def render(self, name, value, attrs=None):
        has_file_set = self.is_initial(value)
        is_required = self.is_required

        file_placeholder = ugettext('Select a file from your local folder.')
        file_input = super().render(name, None, {
            'id': name,
            'class': 'form-control form-control-file'
        })

        if has_file_set:
            file_name = basename(value.name)
            file_url = conditional_escape(value.url)
        else:
            file_name = ""
            file_url = ""

        text_input = widgets.TextInput().render('__noname__', file_name, {
            'class': 'form-control form-control-file-dummy',
            'placeholder': file_placeholder
        })

        checkbox_id = self.clear_checkbox_id(name)
        checkbox_name = self.clear_checkbox_name(name)
        checkbox_input = widgets.CheckboxInput().render(checkbox_name, False, {
            'id': checkbox_id,
            'class': 'clear-image',
            'data-upload-clear': name,
        })

        context = {
            'name': name,
            'has_image_set': has_file_set,
            'is_required': is_required,
            'file_url': file_url,
            'file_input': file_input,
            'file_id': name + '-file',
            'text_input': text_input,
            'checkbox_input': checkbox_input,
            'checkbox_id': checkbox_id
        }

        return mark_safe(
            loader.render_to_string(
                'euth_offlinephases/file_upload_widget.html',
                context
            )
        )