本文整理匯總了Python中django.forms.widgets.CheckboxInput.attrs['disabled']方法的典型用法代碼示例。如果您正苦於以下問題:Python CheckboxInput.attrs['disabled']方法的具體用法?Python CheckboxInput.attrs['disabled']怎麽用?Python CheckboxInput.attrs['disabled']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.forms.widgets.CheckboxInput
的用法示例。
在下文中一共展示了CheckboxInput.attrs['disabled']方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import attrs['disabled'] [as 別名]
def render(self, name, value, attrs=None, choices=()):
if value is None:
value = []
has_id = attrs and 'id' in attrs
final_attrs = self.build_attrs(attrs, name=name)
output = [u'<ul class="multipleCheckBox %s">' % (u'disabled' if len(self.choices) == 0 else u'')]
if len(self.choices) == 0:
output.append(u'<li><label> %s </label></li>' % (_('none available')))
# Normalize to strings
str_values = set([force_unicode(v) for v in value])
for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
# If an ID attribute was given, add a numeric index as a suffix,
# so that the checkboxes don't all have the same ID attribute.
if has_id:
final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
label_for = u' for="%s"' % final_attrs['id']
else:
label_for = ''
chb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
li_class = ''
if isinstance(option_label, dict):
if dict.get(option_label, 'disabled'):
chb.attrs['disabled'] = 'disabled'
li_class = 'disabled'
option_label = option_label['label']
option_value = force_unicode(option_value)
rendered_cb = chb.render(name, option_value)
option_label = conditional_escape(force_unicode(option_label))
output.append(u'<li class="%s"><label%s>%s %s</label></li>' % (li_class, label_for, rendered_cb, option_label))
output.append(u'</ul>')
return mark_safe(u'\n'.join(output))