Ticket #5216: label_tag.5.patch

File label_tag.5.patch, 1.6 KB (added by Vadim Fint <mocksoul@…>, 16 years ago)

Django patch against [8752] with regression test.

  • django/forms/forms.py

     
    371371        """
    372372        contents = contents or escape(self.label)
    373373        widget = self.field.widget
    374         id_ = widget.attrs.get('id') or self.auto_id
     374        id_ = smart_unicode(widget.attrs.get('id', '')) or self.auto_id
    375375        if id_:
    376376            attrs = attrs and flatatt(attrs) or ''
    377377            contents = '<label for="%s"%s>%s</label>' % (widget.id_for_label(id_), attrs, contents)
  • tests/regressiontests/forms/regressions.py

     
    3434u'<p><label for="id_username">Nazwa u\u017cytkownika:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>'
    3535>>> deactivate()
    3636
     37There was some problems with form translations in #5216
     38>>> class SomeForm(Form):
     39...     field_1 = CharField(max_length=10, label=ugettext_lazy('field_1'))
     40...     field_2 = CharField(max_length=10, label=ugettext_lazy('field_2'), widget=TextInput(attrs={'id': 'field_2_id'}))
     41>>> f = SomeForm()
     42>>> print f['field_1'].label_tag()
     43<label for="id_field_1">field_1</label>
     44>>> print f['field_2'].label_tag()
     45<label for="field_2_id">field_2</label>
     46
    3747Unicode decoding problems...
    3848>>> GENDERS = ((u'\xc5', u'En tied\xe4'), (u'\xf8', u'Mies'), (u'\xdf', u'Nainen'))
    3949>>> class SomeForm(Form):
Back to Top