Skip to content

Commit

Permalink
newforms: Added BoundField.data property
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4143 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Nov 29, 2006
1 parent 4a3ad33 commit 61c9384
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion django/newforms/forms.py
Expand Up @@ -182,7 +182,7 @@ def as_widget(self, widget, attrs=None):
auto_id = self.auto_id
if auto_id and not attrs.has_key('id') and not widget.attrs.has_key('id'):
attrs['id'] = auto_id
return widget.render(self._name, self._form.data.get(self._name, None), attrs=attrs)
return widget.render(self._name, self.data, attrs=attrs)

def as_text(self, attrs=None):
"""
Expand All @@ -194,6 +194,11 @@ def as_textarea(self, attrs=None):
"Returns a string of HTML for representing this as a <textarea>."
return self.as_widget(Textarea(), attrs)

def _data(self):
"Returns the data for this BoundField, or None if it wasn't given."
return self._form.data.get(self._name, None)
data = property(_data)

def _verbose_name(self):
return pretty_name(self._name)
verbose_name = property(_verbose_name)
Expand Down
5 changes: 5 additions & 0 deletions tests/regressiontests/forms/tests.py
Expand Up @@ -1268,6 +1268,11 @@
<input type="text" name="first_name" value="John" />
<input type="text" name="last_name" value="Lennon" />
<input type="text" name="birthday" value="1940-10-9" />
>>> for boundfield in p:
... print boundfield.verbose_name, boundfield.data
First name John
Last name Lennon
Birthday 1940-10-9
>>> print p
<tr><td>First name:</td><td><input type="text" name="first_name" value="John" /></td></tr>
<tr><td>Last name:</td><td><input type="text" name="last_name" value="Lennon" /></td></tr>
Expand Down

0 comments on commit 61c9384

Please sign in to comment.