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)
python类TextInput()的实例源码
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)
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)
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)
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)
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)
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)
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)
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)
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(' '))
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))
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)
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)
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)
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
)
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
)
)