Exemple #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 = []
     str_values = set([force_unicode(v)
                       for v in value])  # Normalize to strings.
     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=mixedCaseId('%s%s' % (attrs['id'], i)))
         cb = forms.CheckboxInput(
             final_attrs, check_test=lambda value: value in str_values)
         option_value = force_unicode(option_value)
         rendered_cb = cb.render(name, option_value)
         output.append(
             self.choice_template % {
                 'id': cb.attrs['id'],
                 'label': escape(force_unicode(option_label)),
                 'value': option_value,
                 'control': rendered_cb
             })
     return mark_safe(u'\n'.join(output))
Exemple #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 = []
     str_values = set([force_unicode(v) for v in value])  # Normalize to strings.
     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=mixedCaseId("%s%s" % (attrs["id"], i)))
         cb = forms.CheckboxInput(final_attrs, check_test=lambda value: value in str_values)
         option_value = force_unicode(option_value)
         rendered_cb = cb.render(name, option_value)
         output.append(
             self.choice_template
             % {
                 "id": cb.attrs["id"],
                 "label": escape(force_unicode(option_label)),
                 "value": option_value,
                 "control": rendered_cb,
             }
         )
     return mark_safe(u"\n".join(output))
Exemple #3
0
    def render(self):
        """Outputs some structure for this set of radio fields."""
        id = mixedCaseId(self.name)
        label = self.attrs.get('label', self.name)
        choices = u'\n'.join([
            self.choice_template % {
                'id': '%s_%s' % (id, w.index),
                'label': conditional_escape(force_unicode(w.choice_label)),
                'control': w.tag()
            } for w in self
        ])

        return mark_safe(self.field_wrapper % {
            'id': id,
            'label': label,
            'choices': choices
        })
Exemple #4
0
    def render(self):
        """Outputs some structure for this set of radio fields."""
        id = mixedCaseId(self.name)
        label = self.attrs.get("label", self.name)
        choices = u"\n".join(
            [
                self.choice_template
                % {
                    "id": "%s_%s" % (id, w.index),
                    "label": conditional_escape(force_unicode(w.choice_label)),
                    "control": w.tag(),
                }
                for w in self
            ]
        )

        return mark_safe(self.field_wrapper % {"id": id, "label": label, "choices": choices})