本文整理匯總了Python中django.forms.widgets.CheckboxInput.render方法的典型用法代碼示例。如果您正苦於以下問題:Python CheckboxInput.render方法的具體用法?Python CheckboxInput.render怎麽用?Python CheckboxInput.render使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.forms.widgets.CheckboxInput
的用法示例。
在下文中一共展示了CheckboxInput.render方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [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'<div class="tag-wrapper">']
# 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 = ''
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = force_unicode(option_value)
rendered_cb = cb.render(name, option_value)
option_label = conditional_escape(force_unicode(option_label))
output.append(u'<span class="ui-toggle-button ui-tag">%s<label%s>%s</label></span>' % (rendered_cb, label_for, option_label))
"""
<input type="checkbox" id="check3" /><label for="check3">U</label>
"""
output.append(u'</div>')
return mark_safe(u' '.join(output))
示例2: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [as 別名]
def render(self, name, value, attrs=None, choices=()):
# based entirely on CheckboxSelectMultiple.render, except doesn't use a
# <ul>
if value is None: value = []
has_id = attrs and 'id' in attrs
final_attrs = self.build_attrs(attrs, name=name)
output = [u'<span>']
# 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 = ''
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = force_unicode(option_value)
rendered_cb = cb.render(name, option_value)
option_label = conditional_escape(force_unicode(option_label))
output.append(u'<span><label%s>%s %s</label></span>' % (label_for, rendered_cb, option_label))
output.append(u'</span>')
return mark_safe(u'\n'.join(output))
示例3: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [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>"]
# Normalize to strings
str_values = set([force_unicode(v) for v in value])
for i, (option_value, option_label, option_help_text) 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 = ""
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = force_unicode(option_value)
rendered_cb = cb.render(name, option_value)
option_label = conditional_escape(force_unicode(option_label))
output.append(
u"<li><label%s>%s %s</label><p class='help'>%s</p></li>"
% (label_for, rendered_cb, option_label, option_help_text)
)
output.append(u"</ul>")
return mark_safe(u"\n".join(output))
示例4: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [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'<div class="row">']
# 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 = ''
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = force_unicode(option_value)
rendered_cb = cb.render(name, option_value)
option_label = conditional_escape(force_unicode(option_label))
output.append(u'<div class="span2"><label%s>%s %s</label></div>' % (label_for, rendered_cb, option_label))
ultimo_fila=(((i+1) % 6) == 0)
if ultimo_fila:
output.append(u'</div>')
output.append(u'<div class="row">')
# Normalize to strings
output.append(u'</div>')
return mark_safe(u'\n'.join(output))
示例5: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [as 別名]
def render(self, name, value, attrs=None, choices=()):
if value is None: value = []
has_id = attrs and 'id' in attrs
inline = attrs and attrs.get('inline', False)
final_attrs = self.build_attrs(attrs, name=name)
output = [ ]
str_values = set([force_text(v) for v in value])
for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
if has_id:
final_attrs = dict(final_attrs, id="%s_%s" % (attrs[id], i))
label_for = format_html(' for="{0}"', final_attrs['id'])
else:
label_for = ''
if inline:
label_class = "checkbox inline"
else:
label_class = "checkbox"
label_class = format_html(' class="{0}"', label_class)
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = force_text(option_value)
rendered_cb = cb.render(name, option_value)
option_label = force_text(option_label)
output.append(format_html('<label{0}{1}>{2} {3}</label>',
label_for, label_class, rendered_cb, option_label))
return mark_safe(u'\n'.join(output))
示例6: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [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'<table class="permission_checkbox_table formtable_noborder">']
output.append(u' <tr>')
output.append(u' <th></th>')
output.append(u' <th>Name</th>')
output.append(u' <th>Target</th>')
output.append(u' </tr>')
# Normalize to strings
str_values = set([force_unicode(v) for v in value])
# Original code: multiple permissions were being shown
# for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
for i, (option_value, option_label) in enumerate(chain(set(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))
row_id = u' "row_%s"' % final_attrs['id']
else:
row_id = ''
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = force_unicode(option_value)
rendered_cb = cb.render(name, option_value)
option_label = conditional_escape(force_unicode(option_label))
output.append(u' <tr id=%s>' % row_id)
output.append(u' <td>%s</td>' % rendered_cb)
output.append(u' %s' % option_label)
output.append(u' </tr>')
output.append(u'</table>')
return mark_safe(u'\n'.join(output))
示例7: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [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 = ['<ul class="clear_ul">']
# Normalize to strings
str_values = set([force_text(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 = format_html(' for="{0}"', final_attrs['id'])
else:
label_for = ''
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = force_text(option_value)
rendered_cb = cb.render(name, option_value)
option_label = force_text(option_label)
count = Recipient.objects.filter(group_id=option_value).count()
output.append(format_html('<li class="checkbox-container"><label{0}>{1} {2}</label> <span class="badge group-info">{3}</span></li>',
label_for, rendered_cb, option_label, count))
output.append('</ul>')
return mark_safe('\n'.join(output))
示例8: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [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 = []
# 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 = ''
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = force_unicode(option_value)
# Obtenemos el HTML del widget
rendered_cb = cb.render(name, option_value)
if str_values.intersection([u'JE']) and option_value != 'JE':
# Calculamos la subcadena antes del cierre del tag (' >')
n = len(rendered_cb) - 3
# Añadimos disabled al tag
rendered_cb = rendered_cb[:n] + " disabled" + rendered_cb[n:]
# totales es una lista de enteros con el resumen de las faltas del día
if len(self.totales) > i:
cad = u'<td>%s(%d)</td>' % (rendered_cb, self.totales[i])
else:
cad = u'<td>%s</td>' % rendered_cb
output.append(cad)
return mark_safe(u'\n'.join(output))
示例9: checkbox_inputs
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [as 別名]
def checkbox_inputs(field):
if isinstance(field.field.widget, CheckboxInput):
return [mark_safe(u'<label>%s<span>%s</span></label>' % (field, field.label))]
name = field.name
value = field.value()
attrs = field.field.widget.attrs
choices = field.field.choices
if value is None:
value = []
has_id = attrs and 'id' in attrs
final_attrs = attrs.copy()
final_attrs.update({'name': name})
# Normalize to strings
str_values = set([force_unicode(v) for v in value])
checkbox_inputs = []
disabled_list = []
if isinstance(final_attrs.get('disabled'), collections.Iterable):
disabled_list = final_attrs.pop('disabled')
for i, (option_value, option_label) in enumerate(choices):
_final_attrs = final_attrs.copy()
# 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' % (final_attrs['id'], i))
if option_value in disabled_list:
_final_attrs.update({'disabled': True})
cb = CheckboxInput(_final_attrs, check_test=lambda value: value in str_values)
option_value = force_unicode(option_value)
rendered_cb = cb.render(name, option_value)
checkbox_inputs.append(mark_safe(
u'<label>%s<span>%s</span></label>' % (rendered_cb, option_label)
))
return checkbox_inputs
示例10: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [as 別名]
def render(self, name, value, attrs=None, choices=()):
#print name, value, self.attrs, choices
if value is None: value = []
has_id = attrs and 'id' in attrs
final_attrs = self.build_attrs(attrs, name=name)
#print final_attrs
output = [u'<table id="%s">' % self.table_id]
# Normalize to strings
str_values = set([django.utils.encoding.force_unicode(v) for v in value])
for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
#print option_value, option_label
# 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']
extra_columns_rendered = "".join( [ "<td>%s</td>" % column.render(option_value) for column in self.extra_columns ] )
else:
label_for = u''
extra_columns_rendered = u''
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = django.utils.encoding.force_unicode(option_value)
rendered_cb = cb.render(name, option_value)
option_label = conditional_escape(django.utils.encoding.force_unicode(option_label))
# render the extra columns
output.append(u'<tr><td><label%s>%s</label></td><td>%s</td>%s</tr>' % (label_for, option_label, rendered_cb, extra_columns_rendered))
output.append(u'</table>')
return mark_safe(u'\n'.join(output))
示例11: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [as 別名]
def render(self,name,value,attrs=None,renderer=None,choices=()):
if value is None:
value = []
has_id = attrs and 'id' in attrs
final_attrs = self.build_attrs(attrs) #, name=name)
output = ['<ul>']
str_values = set([v for v in value])
for (i, (option_value, option_label)) in enumerate(chain(self.choices,
choices)):
if has_id:
final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
label_for = ' for="%s"' % final_attrs['id']
else:
label_for = ''
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
rendered_cb = cb.render(name, option_value)
option_label = conditional_escape(option_label)
x = option_label.split('|')
if len(x) > 1:
icon = x[0]
option_label = x[1]
else:
icon = None
if icon:
image = "<img src='%s' />" % icon
else:
image = ''
output.append('<li><label%s>%s %s %s</label></li>' % (label_for,
rendered_cb, image, option_label))
output.append('</ul>')
return mark_safe('\n'.join(output))
示例12: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [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)
items = []
# list of dictionaries, contains:
# extra_class, rendered_cb, content
str_values = set([force_unicode(v) for v in value]) # Normalize to strings.
for i, (option_value, item) in enumerate(self.choices):
option_value = force_unicode(option_value)
check_test = lambda value: value in str_values
# 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))
final_attrs.update({'onClick': 'change_cb(this)'})
cb = CheckboxInput(final_attrs, check_test)
rendered_cb = cb.render(name, option_value)
cb = {"extra_class": 'image_selected' if check_test(option_value) else ""}
cb["rendered_cb"] = rendered_cb
cb["content"] = create_content(item, self.item_attrs)
items.append(cb)
return render_to_string("assets/admin/hero_image.html", {"items": items})
示例13: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [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 = ['<ul class="cols">']
# Normalize to strings
str_values = set([force_text(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:
if option_label.status_unit in (2,):
final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i),)
if 'disabled' in final_attrs:
del final_attrs['disabled']
else:
final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i),)
final_attrs['disabled'] = 'disabled'
label_for = format_html(' for="{0}"', final_attrs['id'])
else:
label_for = ''
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = force_text(option_value)
rendered_cb = cb.render(name, option_value)
option_label = force_text(option_label)
output.append(format_html('<li><label{0}>{1} <span>{2}</span></label></li>',
label_for, rendered_cb, option_label))
output.append('</ul>')
return mark_safe('\n'.join(output))
示例14: render
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [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)
# Normalize to strings
str_values = set([force_unicode(v) for v in value])
output = [u'<div class="groupbox">']
for z, g in enumerate(self.choices):
output.append(u'<div class="groupbox-header">%s <span class="group-count">(<span></span>)</span></div>' % g[0])
output.append(u'<ul class="groupbox-list">')
for i, (option_value, option_label) in enumerate(g[1]):
# 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_%s' % (attrs['id'], z, i))
label_for = u' for="%s"' % final_attrs['id']
else:
label_for = ''
cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
option_value = force_unicode(option_value)
rendered_cb = cb.render(name, option_value)
option_label = conditional_escape(force_unicode(option_label))
output.append(u'<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label))
output.append(u'</ul>')
output.append(u'</div>')
return mark_safe(u'\n'.join(output))
示例15: render_option
# 需要導入模塊: from django.forms.widgets import CheckboxInput [as 別名]
# 或者: from django.forms.widgets.CheckboxInput import render [as 別名]
def render_option(self, attrs, name, selected_choices, option_value, option_label):
container_attrs = attrs['container_attrs']
data_attrs = attrs['data_attrs']
img_url = settings.STATIC_URL+'i/characters/%s.png' % option_value
item_image = '<img src="%s" alt="%s" title="%s" />' % (img_url, option_label, option_label)
cb = CheckboxInput(data_attrs, check_test=lambda x: x in selected_choices)
rendered_cb = cb.render(name, option_value)
return mark_safe(u'<span%s>%s%s</span>' % (flatatt(container_attrs), rendered_cb, item_image))