Permalink
Browse files

Merge pull request #22 from schwuk/master

OptionsRadio (OptionList) widget
  • Loading branch information...
2 parents e522d10 + 4f77969 commit 7d222492f14fc02df00573f8af50fc4b4ebc8b05 @earle earle committed Jan 22, 2012
Showing with 26 additions and 0 deletions.
  1. +26 −0 bootstrap/widgets.py
View
@@ -0,0 +1,26 @@
+from django.forms.widgets import RadioInput, RadioFieldRenderer, RadioSelect
+from django.utils.html import conditional_escape
+from django.utils.encoding import force_unicode
+from django.utils.safestring import mark_safe
+
+
+class OptionsRadioInput(RadioInput):
+ def __unicode__(self):
+ if 'id' in self.attrs:
+ label_for = ' for="%s_%s"' % (self.attrs['id'], self.index)
+ else:
+ label_for = ''
+ choice_label = conditional_escape(force_unicode(self.choice_label))
+ return mark_safe(u'<label%s>%s <span>%s</span></label>' %
+ (label_for, self.tag(), choice_label))
+
+
+class OptionsRadioRenderer(RadioFieldRenderer):
+ def render(self):
+ return mark_safe(u'<ul class="inputs-list">\n%s\n</ul>' %
+ u'\n'.join([u'<li>%s</li>' %
+ force_unicode(w) for w in self]))
+
+
+class OptionsRadio(RadioSelect):
+ renderer = OptionsRadioRenderer

0 comments on commit 7d22249

Please sign in to comment.