def render_options(self, choices, selected_choices, disabled_choices):
        def render_option(option_value, option_label):
            option_value = force_unicode(option_value)
            ## This next line adds a mesasge after the label for the option.  Modify as needed ##
            option_label = (option_value in disabled_choices) and (force_unicode(option_label) + ' - SOLD OUT') or force_unicode(option_label)
            selected_html = (option_value in selected_choices) and ' selected="selected"' or ''
            disabled_html = (option_value in disabled_choices) and ' disabled="disabled"' or ''
            return '<option value="%s"%s%s>%s</option>' % (
                escape(option_value), selected_html, disabled_html,
                conditional_escape(option_label))
        # Normalize to strings.
        selected_choices = set([force_unicode(v) for v in selected_choices])
        disabled_choices = set([force_unicode(v) for v in disabled_choices])
        output = []
        for option_value, option_label in chain(self.choices, choices):
            if isinstance(option_label, (list, tuple)):
                output.append('<optgroup label="%s">' % escape(force_unicode(option_value)))
                for option in option_label:
                    output.append(render_option(*option))
                output.append('</optgroup>')
            else:
                output.append(render_option(option_value, option_label))
        return '\n'.join(output)


##====================================================================================##
Beispiel #2
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))
Beispiel #3
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))
Beispiel #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)
        output = [u'<ul class="inputs-list">']
        # Normalize to strings
        str_values = set([widgets.force_unicode(v) for v in value])
        for i, (option_value, option_label) in enumerate(widgets.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))

            cb = widgets.CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
            option_value = widgets.force_unicode(option_value)
            rendered_cb = cb.render(name, option_value)
            option_label = widgets.force_unicode(option_label)  # purposefully did not escape so I can get html in here
            output.append(u'<li><label>%s<span>%s</span></label></li>' % (rendered_cb, option_label))
        output.append(u'</ul>')
        return widgets.mark_safe(u'\n'.join(output))
Beispiel #5
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="landmarks-listing"><ul class="unstyled">']
        # Normalize to strings
        str_values = set([force_unicode(v) for v in value])
        for i, (option_value, option_label, option_detail) 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)
            option_detail = force_unicode(option_detail)
            rendered_cb = cb.render(name, option_value)
            option_label = conditional_escape(force_unicode(option_label))
            output.append(u'<li><label%s>%s %s</label><div>%s</div></li>' % (label_for, rendered_cb, option_label, option_detail))
        output.append(u'</ul></div><div id="landmark-details"></div><div class="clear"></div>')
        return mark_safe(u'\n'.join(output))
Beispiel #6
0
    def render(self, name, value, attrs=None, choices=()):
        '''
        This render function is copied from django/forms/widgets.py...
        ...and altered several times.
        '''
        attrs = attrs or {}
        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_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),
                                   style='display:inline;')
                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'<label%s style="display:block;">%s %s</label>' %
                          (label_for, rendered_cb, option_label))

        # Optionally wrap it in spans
        COLUMNS, MINVALUES = 3, 8
        if len(output) > MINVALUES:
            per_column = int(float(len(output) + COLUMNS - 1) / COLUMNS)
            for i in reversed(range(per_column, len(output), per_column)):
                output.insert(i, ('</span><span class="column"'
                                  ' style="display:block;">'))
            output.insert(0, ('<span class="large-multiple-choice">'
                              '<span class="column" style="display:block;">'))
            output.append('</span><br style="clear:both;"/></span>')
        else:
            # Always add the large-multiple-choice classes.. otherwise the
            # layout will mismatch.
            output.insert(0, ('<span class="large-multiple-choice">'
                              '<span class="column" style="display:block;">'))
            output.append('</span><br style="clear:both;"/></span>')

        # Code below is from old checkboxselectmultiplewithjs
        buttons = ' / '.join(
            ('''<a href="#" onclick="var checkboxes=document.'''
             '''getElementsByName('%s');'''
             '''for(var i=0;i&lt;checkboxes.length;i++){'''
             '''checkboxes[i].checked=%s;}return false;">%s</a>''') %
            (i[0], i[1], i[2])
            for i in ((name, 'true', 'Select All'), (name, 'false', 'None')))
        output = ('<span class="large-multiple-choice-quickselect">' +
                  buttons + '</span><br/>' + u'\n'.join(output))
        return mark_safe(output)