Add read-only boolean form field widget.
authorTodd Larsen <tlarsen@google.com>
Wed, 14 Jan 2009 22:30:24 +0000
changeset 812 36280f137731
parent 811 9e56019eb218
child 813 68c0eb8656bc
Add read-only boolean form field widget. Developers should be able to view, but not change, the User's agrees_to_tos state. Patch by: Todd Larsen Review by: to-be-reviewed
app/soc/views/helper/widgets.py
--- a/app/soc/views/helper/widgets.py	Wed Jan 14 22:02:39 2009 +0000
+++ b/app/soc/views/helper/widgets.py	Wed Jan 14 22:30:24 2009 +0000
@@ -44,6 +44,21 @@
     return super(ReadOnlyInput, self).render(name, value, attrs)
 
 
+class ReadOnlyBool(forms.widgets.Input):
+  """Read only checkbox widget.
+  """
+  input_type = 'checkbox'
+
+  def render(self, name, value, attrs=None):
+    """Render ReadOnlyBool widget as HTML.
+    """
+    # TODO(tlarsen): this really should display "Yes" or "No" (wrapped with
+    #   ugettext_lazy(), of course), instead of displaying a greyed-out but
+    #   toggleable checkbox (that has no effect on the field, though).
+    attrs['readonly'] = 'readonly'
+    return super(ReadOnlyBool, self).render(name, value, attrs)
+
+
 class TinyMCE(forms.widgets.Textarea):
   """TinyMCE widget.