newforms: Added BoundField.label, which calculates the label of the field based on its name

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4118 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-11-27 04:23:20 +00:00
parent 126e0ec0c3
commit 6d36d97cb8
1 changed files with 6 additions and 2 deletions

View File

@ -81,7 +81,7 @@ class Form(object):
bf = BoundField(self, field, name)
if bf.errors:
output.append(u'<tr><td colspan="2"><ul>%s</ul></td></tr>' % u'\n'.join([u'<li>%s</li>' % e for e in bf.errors]))
output.append(u'<tr><td>%s:</td><td>%s</td></tr>' % (pretty_name(name), bf))
output.append(u'<tr><td>%s:</td><td>%s</td></tr>' % (bf.label, bf))
return u'\n'.join(output)
def as_ul(self):
@ -95,7 +95,7 @@ class Form(object):
line = u'<li>'
if bf.errors:
line += u'<ul>%s</ul>' % u'\n'.join([u'<li>%s</li>' % e for e in bf.errors])
line += u'%s: %s</li>' % (pretty_name(name), bf)
line += u'%s: %s</li>' % (bf.label, bf)
output.append(line)
return u'\n'.join(output)
@ -180,6 +180,10 @@ class BoundField(object):
"Returns a string of HTML for representing this as a <textarea>."
return self.as_widget(Textarea(), attrs)
def _label(self):
return pretty_name(self._name)
label = property(_label)
def _auto_id(self):
"""
Calculates and returns the ID attribute for this BoundField, if the