Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5993 -- Made `RadioSelect` easier to subclass by giving it a d…

…efault `renderer` as a class attribute.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6717 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f110da91dbfa2c9db7e6ef2082b4eb28a7741737 1 parent 183a457
Gary Wilson Jr. authored November 26, 2007
8  django/newforms/widgets.py
@@ -317,11 +317,13 @@ def render(self):
317 317
                 % force_unicode(w) for w in self]))
318 318
 
319 319
 class RadioSelect(Select):
  320
+    renderer = RadioFieldRenderer
320 321
 
321 322
     def __init__(self, *args, **kwargs):
322  
-        self.renderer = kwargs.pop('renderer', None)
323  
-        if not self.renderer:
324  
-            self.renderer = RadioFieldRenderer
  323
+        # Override the default renderer if we were passed one.
  324
+        renderer = kwargs.pop('renderer', None)
  325
+        if renderer:
  326
+            self.renderer = renderer
325 327
         super(RadioSelect, self).__init__(*args, **kwargs)
326 328
 
327 329
     def get_renderer(self, name, value, attrs=None, choices=()):
10  tests/regressiontests/forms/widgets.py
@@ -663,6 +663,16 @@
663 663
 <label><input checked="checked" type="radio" name="beatle" value="G" /> George</label><br />
664 664
 <label><input type="radio" name="beatle" value="R" /> Ringo</label>
665 665
 
  666
+Or you can use custom RadioSelect fields that use your custom renderer.
  667
+>>> class CustomRadioSelect(RadioSelect):
  668
+...    renderer = MyRenderer
  669
+>>> w = CustomRadioSelect()
  670
+>>> print w.render('beatle', 'G', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo')))
  671
+<label><input type="radio" name="beatle" value="J" /> John</label><br />
  672
+<label><input type="radio" name="beatle" value="P" /> Paul</label><br />
  673
+<label><input checked="checked" type="radio" name="beatle" value="G" /> George</label><br />
  674
+<label><input type="radio" name="beatle" value="R" /> Ringo</label>
  675
+
666 676
 A RadioFieldRenderer object also allows index access to individual RadioInput
667 677
 objects.
668 678
 >>> w = RadioSelect()

0 notes on commit f110da9

Please sign in to comment.
Something went wrong with that request. Please try again.