Ticket #11725: django-label-for-none.patch

File django-label-for-none.patch, 848 bytes (added by Denis Martinez <deuns.martinez@…>, 15 years ago)

handle None values from id_for_label

  • django/forms/forms.py

    diff -ru /usr/lib/python2.6/site-packages/django/forms/forms.py django/forms/forms.py
    old new  
    426426        id_ = widget.attrs.get('id') or self.auto_id
    427427        if id_:
    428428            attrs = attrs and flatatt(attrs) or ''
    429             contents = u'<label for="%s"%s>%s</label>' % (widget.id_for_label(id_), attrs, unicode(contents))
     429            id_for_label = widget.id_for_label(id_)
     430            if id_for_label:
     431                contents = u'<label for="%s"%s>%s</label>' % (id_for_label, attrs, unicode(contents))
     432            else:
     433                contents = u'<label%s>%s</label>' % (attrs, unicode(contents))
    430434        return mark_safe(contents)
    431435
    432436    def _is_hidden(self):
Back to Top