mirror of
https://github.com/django/django.git
synced 2025-07-30 16:44:30 +00:00
Changed BoundField.subwidgets() to return SubWidget objects instead of rendered strings. This means we can access individual radio buttons' properties in the template (see new docs)
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17175 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0920165bc2
commit
08bec4fbc1
4 changed files with 62 additions and 7 deletions
|
@ -137,6 +137,22 @@ class MediaDefiningClass(type):
|
|||
new_class.media = media_property(new_class)
|
||||
return new_class
|
||||
|
||||
class SubWidget(StrAndUnicode):
|
||||
"""
|
||||
Some widgets are made of multiple HTML elements -- namely, RadioSelect.
|
||||
This is a class that represents the "inner" HTML element of a widget.
|
||||
"""
|
||||
def __init__(self, parent_widget, name, value, attrs, choices):
|
||||
self.parent_widget = parent_widget
|
||||
self.name, self.value = name, value
|
||||
self.attrs, self.choices = attrs, choices
|
||||
|
||||
def __unicode__(self):
|
||||
args = [self.name, self.value, self.attrs]
|
||||
if self.choices:
|
||||
args.append(self.choices)
|
||||
return self.parent_widget.render(*args)
|
||||
|
||||
class Widget(object):
|
||||
__metaclass__ = MediaDefiningClass
|
||||
is_hidden = False # Determines whether this corresponds to an <input type="hidden">.
|
||||
|
@ -163,7 +179,7 @@ class Widget(object):
|
|||
|
||||
Arguments are the same as for render().
|
||||
"""
|
||||
yield self
|
||||
yield SubWidget(self, name, value, attrs, choices)
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
"""
|
||||
|
@ -623,7 +639,7 @@ class SelectMultiple(Select):
|
|||
data_set = set([force_unicode(value) for value in data])
|
||||
return data_set != initial_set
|
||||
|
||||
class RadioInput(StrAndUnicode):
|
||||
class RadioInput(SubWidget):
|
||||
"""
|
||||
An object used by RadioFieldRenderer that represents a single
|
||||
<input type='radio'>.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue