Пример #1
0
 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) 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 = ''
         if i > 0 and i % 8 == 0:  # if the current iteration is diviible by 7, add a <br />
             output.append(u'<br />')
         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>')
     return mark_safe(u'\n'.join(output))
Пример #2
0
    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))
Пример #3
0
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
Пример #4
0
    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))
Пример #5
0
 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))
Пример #6
0
    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 %s>' % flatatt(self.settings)]
        # 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)
            output.append(
                format_html('<li><label{0}>{1} {2}</label></li>', label_for,
                            rendered_cb, option_label))
        output.append('</ul>')
        return mark_safe('\n'.join(output))
Пример #7
0
    def render(self, name, value, attrs=None, choices=()):
        mark_all=''
        if value is None: 
            value = []
            mark_all = "markall"
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        output = ['<ul class="checkboxes">']
        # Normalize to strings
        str_values = set([force_text(v) for v in value])
        for i, (option_value, option_label) in enumerate(itertools.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 = (option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = force_text(option_label)
            output.append(format_html('<li><label{0}>{1} {2}</label></li>',
                                      label_for, rendered_cb, option_label))
        output.append('</ul>')
        output.append(format_html('<a href="#" data-elemento="{0}" class="checkbutton btn {1}">Desmarcar Todos </a>', name, mark_all))
        return mark_safe('\n'.join(output))
Пример #8
0
    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
0
    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))
Пример #10
0
    def render_checkbox(self, final_attrs, option_value, option_label,
                        str_values, name, label_for):

        from .models import RewardCategory

        checkbox = CheckboxInput(
            final_attrs, check_test=lambda value: value in str_values)
        option_value = force_text(option_value)
        rendered_cb = checkbox.render(name, option_value)
        option_label = force_text(option_label)

        # could do this in one go possibly above
        reward_category = RewardCategory.objects.get(pk=option_value)
        if reward_category.reward_first_ad:
            reward_text = mark_safe(
                u"<span class='alert alert-info' style='padding:2px;'>Voor "
                u"deze categorie geldt een extra waardering *</span>")
            return format_html(
                u'<div class="element checkbox-container"><label{0}>'
                u'{1} {2} - {3}</label>'
                u'</div><div class="clearfix"></div>', label_for,
                rendered_cb, option_label,
                reward_text
            )
        else:
            return format_html(
                u'<div class="element checkbox-container"><label{0}>'
                u'{1} {2}</label><span class="clearfix"></span>'
                u'</div>', label_for,
                rendered_cb, option_label
            )
    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))
Пример #12
0
    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])
        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))
                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))
Пример #13
0
 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
0
    def render_checkbox(self, final_attrs, option_value, option_label,
                        str_values, name, label_for, has_children=False):

        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)

        return u'''<div class="onoffswitch-wrapper">
                %s
                <div class="onoffswitch-wrap">
                    <div class="onoffswitch-text">%s</div>
                    <div class="onoffswitch">
                        %s
                        <label class="onoffswitch-label" %s>
                            <div class="onoffswitch-inner"></div>
                            <div class="onoffswitch-switch"></div>
                        </label>
                    </div>
                    <div class="onoffswitch-text">%s</div>
                </div>
            </div>
            <br clear="all" />
        ''' % (
            option_label, _(u'unblocked'), rendered_cb,
            label_for, _(u'blocked')
        )
Пример #15
0
    def render(self, name, value, attrs=None, choices=()):
        """
        Renders the received choices.
        :param request: SelectMultiple, str, int, list, list
        :return: chain
        """
        if value is None:
            value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'<div>']
        # 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><br>' %
                (label_for, rendered_cb, option_label))
        output.append(u'</div>')
        return mark_safe(u'\n'.join(output))
Пример #16
0
	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))
Пример #17
0
 def render(self, name, value, attrs=None, choices=()):
     """ Rendre le widget """
     if value is None:
         value = []
     has_id = attrs and 'id' in attrs
     final_attrs = self.build_attrs(attrs, name=name)
     output = ['<ul>']
     # Normalize to strings
     str_values = set([str(v) for v in value])
     for i, (option_value, option_label) in enumerate(
             itertools.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='{}_{}'.format(attrs['id'], i))
             label_for = ' for="{}"'.format(final_attrs['id'])
         else:
             label_for = ''
         cb = CheckboxInput(final_attrs,
                            check_test=lambda value: value in str_values)
         option_value = str(option_value)
         rendered_cb = cb.render(name, option_value)
         option_label = conditional_escape(str(option_label))
         output.append('<li>{} <label{}>{}</label></li>'.format(
             rendered_cb, label_for, option_label))
     output.append('</ul>')
     return mark_safe('\n'.join(output))
Пример #18
0
    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))
Пример #19
0
 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})
Пример #20
0
    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>']
        # 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)
            attr_type, attr_shops, sale_name = self._sale_attrs(option_value)
            option_label = ': '.join([sale_name, option_label])
            # 0 is for internet sales.
            shops = ','.join(attr_shops)
            output.append(
                format_html(
                    u'<li product_type={0} shops={1}><label{2}>{3} {4}</label></li>',
                    attr_type, shops, label_for, rendered_cb, option_label))
        output.append('</ul>')
        return mark_safe('\n'.join(output))
Пример #21
0
    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))
Пример #22
0
  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))
Пример #23
0
    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))
Пример #24
0
    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>']
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])

        key = ''
        for i, (option_value,
                option_label) in enumerate(chain(self.choices, choices)):
            if option_value in self.all_fields['user']['fields']:
                key = 'user'
            elif option_value in self.all_fields['membership']['fields']:
                key = 'membership'
            elif option_value in self.all_fields['membership_type']['fields']:
                key = 'membership_type'
            elif option_value in self.all_fields['payment']['fields']:
                key = 'payment'
            elif option_value in self.all_fields['user_group']['fields']:
                key = 'user_group'
            elif option_value in self.all_fields['industry']['fields']:
                key = 'industry'
            elif option_value in self.all_fields['region']['fields']:
                key = 'region'
            elif option_value in self.all_fields['admin']['fields']:
                key = 'admin'
            if key:
                self.all_fields[key]['options'].append(
                    (i, option_value, option_label))
        for key in self.all_fields.keys():
            output.append(u'<div style="clear: both;"></div>')
            output.append(u'<h3>')
            output.append(self.all_fields[key]['title'])
            output.append(u'</h3>')
            output.append(u'<div class="fields-section">')
            for i, option_value, option_label in \
                    self.all_fields[key]['options']:
                # 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="field-box select-field"><label%s>%s %s</label></div>'
                    % (label_for, rendered_cb, option_label))
            output.append(u'</div>')
        output.append(u'</div>')
        return mark_safe(u'\n'.join(output))
Пример #25
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None:
            value = []
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'<ul>']
        str_values = set([force_unicode(v) for v in value])
        for i, (option_value,
                option_label) in enumerate(chain(self.choices, choices)):
            final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
            label_for = u' for="%s"' % final_attrs['id']

            # Caso exista uma pergunta para abrir
            # adiciona um atripbuto no checkbox
            schema_to_open = Escolha.objects.get(
                pk=option_value).schema_to_open
            if schema_to_open:
                final_attrs['schema_to_open'] = schema_to_open.name

            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>')
        return mark_safe(u'\n'.join(output))
Пример #26
0
 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)
     output = ["<ul>"]
     str_values = set([str(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: str(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))
Пример #27
0
    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) 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 = ''

            town_id = option_value
            if town_id in self.sda_mapping['town_maps'].keys() and self.sda_mapping['town_maps'][town_id] != '':
                rendered_map_button = """<button class='sda_map_button' onclick='return emerald.show_sda_map(event, "%s")'>map</button>""" % town_id
            else:
                rendered_map_button = """<button class='sda_map_button_disabled' onclick='return false'>map</button>"""

            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 %s</label></li>' % (label_for, rendered_map_button, rendered_cb, option_label))
        output.append(u'</ul>')
        return mark_safe(u'\n'.join(output))
Пример #28
0
    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_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 = u' for="%s"' % 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 = conditional_escape(force_text(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))
Пример #29
0
    def render(self, name, value, attrs=None, choices=()):
        PERSON_COL = 3
        tmpcol = 1
        old_group = None

        if value is None: value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'<table width="100%">']
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])

        for i, (option_value, user) 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)
            rendered_cb = cb.render(name, force_unicode(option_value))

            #do group
            if old_group != user.get_profile().company:
                if tmpcol > 1:
                    for i in range(tmpcol, PERSON_COL + 1):
                        output.append('<td></td>')
                    output.append(u'</tr>')

                output.append(
                    u'<tr><td colspan="%(col)s"><p style="margin: 15px 0 10px 0;"><a class="smallcaps_title blue_bg white" href="">%(name)s</a></p></td></tr>'
                    % {
                        'col': PERSON_COL,
                        'name': user.get_profile().company.short_name
                    })
                tmpcol = 1
                old_group = user.get_profile().company
            #do user
            u = self.myrender(user, label_for, rendered_cb)
            if tmpcol == 1:
                u = '<tr>' + u
                tmpcol += 1
            elif tmpcol == PERSON_COL:
                u += '</tr>'
                tmpcol = 1
            else:
                tmpcol += 1
            output.append(u)

        if tmpcol > 1:
            for i in range(tmpcol, PERSON_COL + 1):
                output.append('<td></td>')
            output.append(u'</tr>')
        output.append(u'</table>')

        return mark_safe(u'\n'.join(output))
Пример #30
0
 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))
Пример #31
0
 def render_title(self, writer, name, attrs=None):
     if self.field.check_all and isinstance(writer, HtmlWriter):
         final_attrs = self.build_title_attrs(base_css=self.css, extra_css=(name.replace('_', '-'),))
         tip = ' <i class="icon-question-sign"></i>' if 'data-tip' in final_attrs else ''
         cb = CheckboxInput({'class': 'datatables-checkall', 'data-checkall': self.field.form_field_name})
         title = cb.render('_%s_check_all' % self.field.form_field_name, False)
         return format_html(u'<span{0} >{1}{2}</span>', flatatt(final_attrs), title, mark_safe(tip))
     else:
         return super(CheckboxWidget, self).render_title(writer, name, attrs)
Пример #32
0
    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="checkbox-group-root">']
        # Normalize to strings
        str_values = set([force_text(v) for v in value])
        for i, (group_name, items) 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:
                group_attrs = dict(final_attrs, id='%s_group_%s' % (attrs['id'], i), **{'class': 'checkbox-group'})
                label_for = format_html(' for="{0}"', group_attrs['id'])
            else:
                group_attrs = final_attrs
                label_for = ''

            cb = CheckboxInput(group_attrs, check_test=lambda value: value in str_values)
            if group_name is None:
                group_name = 'Нет группы'
            rendered_cb = cb.render('', group_name)
            group_name = force_text(group_name)
            item_count = len(items)
            output.append(format_html('<li class="checkbox-group-container"><div class="checkbox-group-div"><label{0} class="checkbox-group-label">{1} {2}</label> <span class="badge group-info">{3}</span><span class="group-toggle glyphicon glyphicon-chevron-down pull-right"></span></div>',
                                      label_for, rendered_cb, group_name, item_count))
            output.append('<ul class="checkbox-group-items">')
            for j, (option_value, option_label) in enumerate(items):
                if has_id:
                    item_attrs = dict(final_attrs, id='%s_%s_group_%s' % (attrs['id'], j, i), **{'class': 'checkbox-item'})
                    label_for = format_html(' for="{0}"', item_attrs['id'])
                else:
                    item_attrs = final_attrs
                    label_for = ''
                cb = CheckboxInput(item_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 class="label_text">{2}</span></label></li>',
                                          label_for, rendered_cb, option_label))
            output.append('</ul>')
            output.append('</li>')
        output.append('</ul>')
        return mark_safe('\n'.join(output))
Пример #33
0
    def render_checkbox(self, final_attrs, option_value, option_label,
                        str_values, name, label_for):
        checkbox = CheckboxInput(final_attrs,
                                 check_test=lambda value: value in str_values)
        option_value = force_text(option_value)
        rendered_cb = checkbox.render(name, option_value)
        option_label = force_text(option_label)

        return format_html(
            '<li><div class="element checkbox-container"><label{0}>'
            '{1} {2}</label></div></li>', label_for, rendered_cb, option_label)
Пример #34
0
    def render(self, name, value, attrs=None, choices=()):
        PERSON_COL=3
        tmpcol = 1
        old_group = None

        if value is None: value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'<table width="100%">']
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])

        for i, (option_value, user) 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)
            rendered_cb = cb.render(name, force_unicode(option_value))

            #do group
            if old_group != user.get_profile().company:
                if tmpcol > 1 :
                    for i in range(tmpcol, PERSON_COL+1 ):
                        output.append( '<td></td>' )
                    output.append(u'</tr>')

                output.append(  u'<tr><td colspan="%(col)s"><p style="margin: 15px 0 10px 0;"><a class="smallcaps_title blue_bg white" href="">%(name)s</a></p></td></tr>'%{'col': PERSON_COL, 'name': user.get_profile().company.short_name} )
                tmpcol = 1
                old_group = user.get_profile().company
            #do user
            u = self.myrender(user, label_for, rendered_cb)
            if tmpcol == 1:
                u = '<tr>' + u
                tmpcol  += 1
            elif tmpcol == PERSON_COL:
                u += '</tr>'
                tmpcol = 1
            else:
                tmpcol  += 1
            output.append( u  )

        if tmpcol > 1 :
            for i in range(tmpcol, PERSON_COL+1 ):
                output.append( '<td></td>' )
            output.append(u'</tr>')
        output.append(u'</table>')

        return mark_safe(u'\n'.join(output))
Пример #35
0
    def render_checkbox(self, final_attrs, option_value, option_label,
                        str_values, name, label_for):
        checkbox = CheckboxInput(final_attrs,
                                 check_test=lambda value: value in str_values)
        option_value = force_text(option_value)
        rendered_cb = checkbox.render(name, option_value)
        option_label = force_text(option_label)

        return format_html(
            '<div class="form-group"><div class="checkbox">'
            '<label{0}>{1}<span> {2}</span></label></div></div>', label_for,
            rendered_cb, option_label)
Пример #36
0
    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)

        tab_id = 1
        active = 'active'
        output = [u'<div class="tab-content">', ]
        initial_qs = self.choices.queryset

        nav = ['<ul class="nav nav-tabs">', ]

        for tab in 'general, NHL, CFL, MLS, MLB, WNBA, NBA, NFL, UEFA-English, college-div1'.split(', '):
            nav.append('<li class="%s">' % active)
            nav.append('<a href="#%s-tab%d" data-toggle="tab">%s</a>' % (
            name, tab_id, tab.replace('college-div1', 'College Div1')))
            nav.append('</li>')

            output = output + [u'<div class="tab-pane %s" id="%s-tab%d">' % (active, name, tab_id), u'<ul>']
            tab_id += 1
            if tab_id != 1:
                active = ''

            # Normalize to strings
            str_values = set([force_unicode(v) for v in value])
            self.choices.queryset = initial_qs.filter(sub_category=tab)
            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_%s' % (attrs['id'], i, tab.lower()))
                    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>')

        nav.append('</ul>')

        output.append(u'</div>')

        output = nav + output

        return mark_safe(u'\n'.join(output))
Пример #37
0
    def render(self, name, value, attrs=None):
        value = [] if value is None else value
        output = []
        output.append(u'<table class="services_properties wide center">')
        for srv in self.services:
            output.append(u'<tr><th colspan="%s">%s</th></tr>' %
                (self.COLUMNS * 2, srv.get('name')))

            js_cb_all = u'''<script type="text/javascript">
                $("#%(id)s_all").click(function() {
                    var checked_status = this.checked;
                    $("input[name^=%(id)s]").each(function() {
                        this.checked = checked_status;
                    });
                });
                </script>''' % ({'id': srv['id']})

            id_all = '%s_all' % srv['id']
            attrs = {'id': id_all}
            label_for = u' for="%s"' % id_all
            cb = CheckboxInput(attrs)
            rendered_cb = cb.render(id_all, id_all in self.sel_props)
            output.append(u'<tr><td colspan="%s">%s <label%s>%s</label> %s</td></tr>' %
                (self.COLUMNS * 2, rendered_cb, label_for, _('select all'), js_cb_all))

            props = srv['properties']
            rendered_props = []
            for p in props:
                id = '%s_%s' % (srv['id'], p)
                attrs = {'id': id}
                label_for = u' for="%s"' % id
                cb = CheckboxInput(attrs)
                rendered_cb = cb.render(id, id in self.sel_props)
                rendered_props.append((rendered_cb, u'<label%s>%s</label>' % (label_for, p)))
            output.append(elems_as_table(rendered_props, self.COLUMNS))
        output.append(u'</table><br>')
        return mark_safe(u'\n'.join(output))
Пример #38
0
 def render(self, report, writer, name, value, item, row_number, attrs=None, **kwargs):
     """
     Render a select form field
     """
     if not isinstance(writer, HtmlWriter):
         return value
     if value is None:
         value = ''
     final_attrs = self.get_form_element_attributes(item, report._meta.form_prefix, self.field.form_field_name, row_number, value)
     cb = CheckboxInput(final_attrs) #, check_test=lambda value: value in str_values)
     try:
         checked = str(value) in kwargs['form_field_value']
     except KeyError:
         checked = False
     return cb.render(self.field.form_field_name, checked)
Пример #39
0
    def render(self, name, value, attrs=None, choices=()):
        spis_available_rules_choice = []
        spis_mandatory_rules_choice = []
        available_rule_qs = Rules_for_restore_zakaz.objects.filter(service_type=self.attrs['service_type_init'])
        if available_rule_qs:
            for i in available_rule_qs[0].rules.all().order_by('name_rule'):
                spis_available_rules_choice.append(i.id)
            for i in available_rule_qs[0].mandatory_rules.all().order_by('name_rule'):
                spis_mandatory_rules_choice.append(i.id)

        if value is None: value = []
        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name,)
        output = ['<ul class="cols" id="id_spis_rules">']
        # 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_value in spis_available_rules_choice:
                    rule_obj = Spis_rules_for_restore_zakaz.objects.get(id=option_value)
                    final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i),)
                    if 'checked' in final_attrs:
                        del final_attrs['checked']
                    if 'onclick' in final_attrs:
                        del final_attrs['onclick']
                    if 'disabled' in final_attrs:
                        del final_attrs['disabled']
                    if option_value in spis_mandatory_rules_choice:
                        final_attrs['checked'] = 'checked'
                        final_attrs['onclick'] = 'window.event.returnValue=false'
                    if rule_obj.action_on_change:
                        final_attrs['onclick'] = 'check_rule(this, "%s")' % rule_obj.action_on_change
                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(u'<li><label{0}>{1} <span>{2}</span></label></li>',
                                      label_for, rendered_cb, option_label))
        output.append('</ul>')
        return mark_safe('\n'.join(output))
Пример #40
0
    def render(self, name, value, attrs=None, choices=()):
        """
        Renderiza o Widget
        retorna o codigo html da selecao
        """

        if value is None: value = []
        final_attrs = self.build_attrs(attrs, name=name)
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])

        output = [
            u'<h4 class="cleantitle">Personalizando permissões</h4><table class="table table-bordered">',
        ]
        headers = [u'<th>Módulo</th>']

        for header in PERMISSIONS_HEADERS:
            headers.append(u'<td class="final">%s</td>' % header)

        output.append(u'<thead><tr>%s</tr></thead>' % u'\n'.join(headers))
        classes = cycle(['lr', 'lt'])

        for label, perms in self.get_permissions():
            row = [u'<td>%s</td>' % label]
            mod = perms[0].split('.', 2)[0]

            for p in PERMISSIONS_NAMES:
                perm = '%s.%s' % (mod, p)

                if perm in perms:
                    final_attrs = dict(final_attrs,
                                       id='%s_%s' % (attrs['id'], perm))
                    cb = CheckboxInput(
                        final_attrs,
                        check_test=lambda value: value in str_values)
                    row.append(u'<td class="choice">%s</td>' %
                               cb.render(name, perm))
                else:
                    row.append(u'<td> </td>')

            output.append(u'<tr class="{0}">{1}</tr>'.format(
                classes.next(), u'\n'.join(row)))

        output.append(u'</table>')

        return mark_safe(u'\n'.join(output))
Пример #41
0
    def render_to_list(self, name, value, attrs=None, choices=(), keep_desc=True):
        """
        Return list of HTML strings for each checkbox
        Param: value -- either a list of checkboxes to check off or a comma-seperated string of list checkboxes to check off.
        """
        #print "render_to_list(%s) value: %s\t\tattrs=%s\n\tchoices=%s" % (name, value, attrs, choices)
        
        if value is None: value = []
        if not isinstance(value, list):
            if isinstance(value,int):
                value = [value]
            else:
                value = value.split(",")

        has_id = attrs and 'id' in attrs
        final_attrs = self.build_attrs(attrs, name=name)
        #print "\tfinal_attrs = %s" % ( final_attrs, )
        output = []
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])
        #print "\tstr_values = %s" % ( str_values, )
        
        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)
            if keep_desc:
                option_label = conditional_escape(force_unicode(option_label))
            else:
                option_label = ""
            #print "option_value", option_value
            #print "rendered_cb", rendered_cb
            #print "label_for", label_for
            output.append(u'<label%s>%s%s</label>' % (label_for, rendered_cb, option_label))
        
        return output
Пример #42
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None:
            value = []

        has_id = attrs and 'id' in attrs
        attrs.update({u'name':name})
        final_attrs = self.build_attrs(attrs)

        grouped_list = []
        for order_key, elems in self.grouped.items():
            fieldset = '<fieldset class="%s"><legend>%s</legend><ul>' \
                % (self.css_class, order_key.title())
            output = [fieldset]

            # Normalize to strings
            str_values = set([force_text(v) for v in value])

            for i, obj in enumerate(elems):
                option_value, option_label = obj.pk, obj.__unicode__()
                # 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'], i, order_key)
                    )
                    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} {2}</label></li>',
                                label_for, rendered_cb, option_label)
                )
            output.append('</ul></fieldset>')
            grouped_list.append('\n'.join(output))

        return mark_safe('\n'.join(grouped_list))
    def _render_li(
        self, option_value, option_label, final_attrs, suffix, str_values, subchoices=(), superchecked=False
    ):

        # If an ID attribute was given, add the suffix,
        # so that the checkboxes don't all have the same ID attribute.
        has_id = "id" in final_attrs
        if has_id:
            sub_attrs = dict(final_attrs, id="%s_%s" % (final_attrs["id"], suffix))
            label_for = u' for="%s"' % sub_attrs["id"]
        else:
            sub_attrs = final_attrs
            label_for = ""

        option_value = force_unicode(option_value)
        checked = lambda value: value in str_values

        li = [u"<li>"]
        li_classes = []
        if checked(option_value):
            li_classes.append("checked")
        if superchecked:
            li_classes.append("superchecked")

        cb = CheckboxInput(sub_attrs, check_test=checked)
        rendered_cb = cb.render(sub_attrs["name"], option_value)
        option_label = conditional_escape(force_unicode(option_label))
        li.append(u"<label%s>%s %s</label>" % (label_for, rendered_cb, option_label))

        subchecked = False
        if subchoices:
            if checked(option_value):
                superchecked = True
            sublist, subchecked = self._render_ul(subchoices, sub_attrs, str_values, superchecked)
            li.append(sublist)
        if subchecked:
            li_classes.append("subchecked")

        li.append(u"</li>")
        if li_classes:
            li[0] = u'<li class="%s">' % u" ".join(li_classes)
        return (u"\n".join(li), checked(option_value), subchecked)
Пример #44
0
 def render_checkbox(self,
                     final_attrs,
                     option_value,
                     option_label,
                     str_values,
                     name,
                     label_for,
                     has_children=False):
     checkbox = CheckboxInput(final_attrs,
                              check_test=lambda value: value in str_values)
     option_value = force_text(option_value)
     rendered_cb = checkbox.render(name, option_value)
     option_label = force_text(option_label)
     if has_children:
         post_label = ' <span class="toggle-sub-categories">&nbsp;</span>'
     else:
         post_label = ''
     return u'<div class="element checkbox-container"><label{0}>' \
            u'{1} {2}</label>{3}</div>'.format(
                label_for, rendered_cb, option_label, post_label)
Пример #45
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None:
            value = []

        has_id = attrs and 'id' in attrs
        attrs.update({u'name': name})
        final_attrs = self.build_attrs(attrs)

        grouped_list = []
        for order_key, elems in self.grouped.items():
            fieldset = '<fieldset class="%s"><legend>%s</legend><ul>' \
                % (self.css_class, order_key.title())
            output = [fieldset]

            # Normalize to strings
            str_values = set([force_text(v) for v in value])

            for i, obj in enumerate(elems):
                option_value, option_label = obj.pk, obj.__unicode__()
                # 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'], i, order_key))
                    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} {2}</label></li>',
                                label_for, rendered_cb, option_label))
            output.append('</ul></fieldset>')
            grouped_list.append('\n'.join(output))

        return mark_safe('\n'.join(grouped_list))
Пример #46
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None: value = []
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'<ul>']
        str_values = set([force_unicode(v) for v in value])
        i = 0
        for sistema in self.servicios:
            output.append(u"<h3>%s</h3>" % sistema["sistema"])
            choices = [(servicio.id, servicio.nombre) for servicio in sistema["servicios"]]
            for (option_value, option_label) in choices:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = u' for="%s"' % final_attrs['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'<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label))
                i += 1
        output.append(u'</ul>')

        return mark_safe(u'\n'.join(output))
Пример #47
0
    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) in enumerate(chain(self.choices, choices)):
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))

            checkbox = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            option_value = force_unicode(option_value)
            rendered_checkbox = checkbox.render(name, option_value)
            option_label = conditional_escape(force_unicode(option_label))
            output.append(u'<li id="filter_val_%s" title="%s">%s<p>%s</p></li>' % (option_value.lower(),
                                                                                   option_label.title(),
                                                                                   rendered_checkbox,
                                                                                   option_label))
        output.append(u'</ul>')
        return mark_safe(u'\n'.join(output))
Пример #48
0
 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>']
     # Normalize to strings
     str_values = set([force_unicode(v) for v in value])
     # build table
     all_choices = list(chain(self.choices, choices))
     rows_count = math.ceil(len(all_choices) / float(self.cols_count)) 
     for row in range(0, rows_count):
         start = row*self.cols_count
         output.append(u'<tr>')
         for i in range(start, start+self.cols_count):
             if i >= len(all_choices):
                 output.append(u'<td>&nbsp;</td>')
             else:
                 (option_value, option_label) = all_choices[i]
                 output.append(u'<td>')
                 # 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><img src="%s"/></div>' % self.thumb_urls[i]) 
                 output.append(u'<div><label%s>%s %s</label></div>' % (label_for, rendered_cb, option_label))
                 output.append(u'</td>')
         output.append(u'</tr>')
    
     output.append(u'</table>')
     
     return mark_safe(u'\n'.join(output))
Пример #49
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None: value = []
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'<ul>']
        str_values = set([force_unicode(v) for v in value])
        for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
            final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
            label_for = u' for="%s"' % final_attrs['id']

            # Caso exista uma pergunta para abrir
            # adiciona um atripbuto no checkbox
            schema_to_open = Escolha.objects.get(pk=option_value).schema_to_open
            if schema_to_open:
                final_attrs['schema_to_open'] = schema_to_open.name

            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>')
        return mark_safe(u'\n'.join(output))
Пример #50
0
    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)
            rendered_cb = cb.render(name, option_value)
            option_label = conditional_escape(force_unicode(option_label))
            output.append(u'<td class="input_td">%s</td>' % (rendered_cb,))
        return mark_safe(u'\n'.join(output))
Пример #51
0
    def render(self, name, value, attrs=None, choices=()):
        if value is None: 
            value = []
        final_attrs = self.build_attrs(attrs, name=name)
        output = [u'']
        # 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 attrs and 'id' in attrs:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))
                label_for = u' for="%s"' % final_attrs['id']
            else:
                label_for = ''

            checkbox = CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            option_value = force_unicode(option_value)
            rendered_cb = checkbox.render(name, option_value)
            option_label = conditional_escape(force_unicode(option_label))
            output.append(u'<li>%s <label%s>%s</label></li>' % (rendered_cb, label_for, option_label))
        output.append(u'')
        return mark_safe(u'\n'.join(output))
Пример #52
0
 def render(self, name, value, attrs=None):
     if value is None:
         value = []
     value = map(int, value)
     attrs = self.attrs
     label_attrs = attrs.pop('label_attrs', None)
     label_id_related_attr = attrs.pop('label_id_related_attr', False)
     output = []
     if label_attrs is not None:
         label_class = '%s' % join(label_attrs, ' ')
     else:
         label_class = ''
     for (option_value, option_label) in self.choices:
         cb = CheckboxInput(attrs, check_test=lambda x: x in value)
         rendered_cb = cb.render(name, option_value)
         option_label = force_unicode(option_label)
         if label_id_related_attr:
             label_id_related_class = ' '+label_id_related_attr+'%s ' % option_value
         else:
             label_id_related_class = ''
         label_class_final = ' class="%s%s"' % (label_class, label_id_related_class)
         output.append(u'<label%s>%s %s</label>' % (label_class_final, rendered_cb, option_label))
     return mark_safe(u'\n'.join(output))
Пример #53
0
    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) in enumerate(chain(self.choices, choices)):
            if has_id:
                final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i))

            checkbox = CheckboxInput(
                final_attrs, check_test=lambda value: value in str_values)
            option_value = force_unicode(option_value)
            rendered_checkbox = checkbox.render(name, option_value)
            option_label = conditional_escape(force_unicode(option_label))
            output.append(
                u'<li id="filter_val_%s" title="%s">%s<p>%s</p></li>' %
                (option_value.lower(), option_label.title(), rendered_checkbox,
                 option_label))
        output.append(u'</ul>')
        return mark_safe(u'\n'.join(output))
Пример #54
0
    def render(self, name, value, attrs=None, choices=()):
        """
        Renders the widget.

        @rtype: unicode
        @return: html tablerows (<tr>) each containing a checkbox with the
        candidate's name and picture beside it.
        """
        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 = ''
            # Does the candidate have a picture?
            if self.choices.queryset.get(pk=option_value).picture:
                pictureurl = unicode(self.choices.queryset.get(pk=option_value).picture.url)
            else:
                pictureurl = ''
            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>'\
                                '<td><label%s>%s %s</label></td>'\
                                '<td><img src="%s" class="candidate_picture" /></td>'\
                           '</tr>' % \
                           (label_for, rendered_cb, option_label, pictureurl))
        return mark_safe(u'\n'.join(output))
Пример #55
0
    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))
Пример #56
0
 def render(self, name, value, attrs=None):
     if value is None:
         value = []
     attrs = self.attrs
     btn_attrs = attrs.pop('btn_attrs', {})
     data_attrs = attrs.pop('data_attrs', {})
     btn_container_attrs = attrs.pop('btn_container_attrs', {})
     data_container_attrs = attrs.pop('data_container_attrs', {})
     btn_container = []
     data_container = []
     output = []
     for (option_value, option_label) in self.choices:
         option_label = force_unicode(option_label)
         btn = ButtonWidget(attrs=dict(btn_attrs, text=option_label, value=option_value))
         rendered_btn = btn.render(attrs=btn_attrs)
         btn_container.append(rendered_btn)
         cb = CheckboxInput(data_attrs, check_test=lambda x: x in value)
         rendered_cb = cb.render(name, option_value)
         data_container.append(rendered_cb)
     btn = '<div%s>%s</div>' % (flatatt(btn_container_attrs), join(btn_container))
     data = '<div%s>%s</div>' % (flatatt(data_container_attrs), join(data_container))
     output.append(btn)
     output.append(data)
     return mark_safe(u'\n'.join(output))
Пример #57
0
    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)

        # No groups in widget so render checkboxes in normal way
        if 'groups' not in final_attrs:
            output = []
            # 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)
                output.append(
                    '<div class="checkbox"><label%s>%s %s</label></div>' %
                    (label_for, rendered_cb, option_label))
            return mark_safe('\n'.join(output))

        output = []
        groups = final_attrs['groups']

        if 'groups' in final_attrs:
            del final_attrs['groups']

        for group_index, group in enumerate(groups):
            str_values = set([force_text(v) for v in value])
            group_id = 'group_%i' % group_index

            result = ['<ul class="list-group">']

            has_opened_checkboxes = False
            for checkbox_index, (option_value, option_label) in enumerate(
                    group[1]['choices']):
                if has_id:
                    final_attrs = dict(
                        final_attrs,
                        id='%s_%s_%s' %
                        (attrs['id'], group_index, checkbox_index))
                    label_for = format_html(' for="{0}"', final_attrs['id'])
                else:
                    label_for = ''

                cb = CheckboxInput(
                    final_attrs, check_test=lambda value: value in str_values)
                if cb.check_test(str(option_value)):
                    has_opened_checkboxes = True
                    break

            open_group = False
            for checkbox_index, (option_value, option_label) in enumerate(
                    group[1]['choices']):
                if has_id:
                    final_attrs = dict(
                        final_attrs,
                        id='%s_%s_%s' %
                        (attrs['id'], group_index, checkbox_index))
                    label_for = format_html(' for="{0}"', final_attrs['id'])
                else:
                    label_for = ''

                if 'on_check' in final_attrs:
                    del final_attrs['on_check']

                if has_opened_checkboxes is False and 'predefined_values_on_check' in group[
                        1]:
                    predefined_values = group[1]['predefined_values_on_check']

                    if type(predefined_values) == str:
                        if predefined_values == 'all':
                            final_attrs['on_check'] = 'checked'
                    elif type(predefined_values) == list or type(
                            predefined_values) == tuple:
                        if option_value in predefined_values:
                            final_attrs['on_check'] = 'checked'

                cb = CheckboxInput(
                    final_attrs, check_test=lambda value: value in str_values)

                if cb.check_test(str(option_value)):
                    open_group = True

                option_value = force_text(option_value)
                rendered_cb = cb.render(name, option_value)
                option_label = force_text(option_label)
                result.append(
                    '<li class="list-group-item"><div class="checkbox"><label%s>%s %s</label></div></li>'
                    % (label_for, rendered_cb, option_label))
            result.append('</ul>')

            output.append(
                '<div class="group %(classes)s"><div class="panel panel-primary"><div class="panel-heading">%(heading)s</div>%(result)s</div></div>'
                % {
                    'heading':
                    '<h4 class="panel-title checkbox"><label for="%(group_id)s">%(title)s</label></h4><a href="#" class="toggler"></a>'
                    % {
                        'group_id':
                        group_id,
                        'title':
                        CheckboxInput().render(
                            group_id, open_group, attrs={
                                'id': group_id,
                            }) + group[0],
                    },
                    'classes':
                    ' '.join(group[1]['classes'])
                    if 'classes' in group[1] else '',
                    'result':
                    '\n'.join(result),
                })

        return mark_safe('\n'.join(output))