本文整理汇总了Python中django.forms.widgets.CheckboxInput方法的典型用法代码示例。如果您正苦于以下问题:Python widgets.CheckboxInput方法的具体用法?Python widgets.CheckboxInput怎么用?Python widgets.CheckboxInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.widgets
的用法示例。
在下文中一共展示了widgets.CheckboxInput方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import CheckboxInput [as 别名]
def render(self, name, value, attrs=None,):
substitutions = {
'clear_checkbox_label': self.clear_checkbox_label,
'initial' : '<img class="img-responsive img-thumbnail" width="%s" src="%s">' % (
force_text('100%'),
force_text(get_thumbnailer(value)['medium'].url if value and hasattr(value, 'url') else static('images/placeholder.svg'))
)
}
template = '%(initial)s%(input)s'
substitutions['input'] = super(ClearableFileInput, self).render(name, value, attrs)
if not self.is_required:
template = '%(initial)s%(clear_template)s%(input)s'
checkbox_name = self.clear_checkbox_name(name)
checkbox_id = self.clear_checkbox_id(checkbox_name)
substitutions['clear_checkbox_name'] = conditional_escape(checkbox_name)
substitutions['clear_checkbox_id'] = conditional_escape(checkbox_id)
substitutions['clear'] = CheckboxInput().render(checkbox_name, False, attrs={'id': checkbox_id})
substitutions['clear_template'] = self.clear_checkbox_name(checkbox_name)
return mark_safe(template % substitutions)
示例2: __init__
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import CheckboxInput [as 别名]
def __init__(self, *args, **kwargs):
super(BootsrapForm, self).__init__(*args, **kwargs)
for field in self.fields.values():
# Only tweak the field if it will be displayed
if not isinstance(field.widget, widgets.HiddenInput):
attrs = {}
if (
isinstance(field.widget, (widgets.Input, widgets.Select, widgets.Textarea)) and
not isinstance(field.widget, (widgets.CheckboxInput,))
):
attrs['class'] = "form-control"
if isinstance(field.widget, (widgets.Input, widgets.Textarea)) and field.label:
attrs["placeholder"] = field.label
if field.required:
attrs["required"] = "required"
field.widget.attrs.update(attrs)
示例3: test_DictCharWidget_renders_with_empty_string_as_input_data
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import CheckboxInput [as 别名]
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]
)
示例4: bootstrap_input_type
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import CheckboxInput [as 别名]
def bootstrap_input_type(field):
"""
Return input type to use for field
"""
try:
widget = field.field.widget
except:
raise ValueError("Expected a Field, got a %s" % type(field))
input_type = getattr(widget, 'bootstrap_input_type', None)
if input_type:
return str(input_type)
if isinstance(widget, TextInput):
return u'text'
if isinstance(widget, CheckboxInput):
return u'checkbox'
if isinstance(widget, CheckboxSelectMultiple):
return u'multicheckbox'
if isinstance(widget, RadioSelect):
return u'radioset'
return u'default'
示例5: is_checkbox
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import CheckboxInput [as 别名]
def is_checkbox(field):
return isinstance(field.field.widget, CheckboxInput)
示例6: value_from_datadict
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import CheckboxInput [as 别名]
def value_from_datadict(self, data, files, name):
"""
Modify value_from_datadict, so that delete takes precedence over
upload.
"""
file_value = super(widgets.ClearableFileInput, self)\
.value_from_datadict(data, files, name)
checkbox_value = widgets.CheckboxInput()\
.value_from_datadict(data, files, self.clear_checkbox_name(name))
if not self.is_required and checkbox_value:
return False
return file_value
示例7: test_DictCharWidget_renders_fieldset_with_label_and_field_names
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import CheckboxInput [as 别名]
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],
)
示例8: test_empty_DictCharWidget_renders_as_empty_string
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import CheckboxInput [as 别名]
def test_empty_DictCharWidget_renders_as_empty_string(self):
widget = DictCharWidget(
[widgets.CheckboxInput], [], [], [], skip_check=True
)
self.assertEqual("", widget.render(factory.make_string(), ""))
示例9: render
# 需要导入模块: from django.forms import widgets [as 别名]
# 或者: from django.forms.widgets import CheckboxInput [as 别名]
def render(self, name, value, attrs=None, renderer=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
)