Author: carndt
Date: Mon Jul 23 09:40:10 2007
New Revision: 3351
URL: http://trac.turbogears.org/changeset/3351

Log:
Use "default" param in CheckBox widget example

Modified:
   branches/1.0/turbogears/widgets/forms.py
   branches/1.1/turbogears/widgets/forms.py

Modified: branches/1.0/turbogears/widgets/forms.py
==============================================================================
--- branches/1.0/turbogears/widgets/forms.py    (original)
+++ branches/1.0/turbogears/widgets/forms.py    Mon Jul 23 09:40:10 2007
@@ -12,11 +12,11 @@
 __all__ = ["InputWidget", "CompoundInputWidget", "RepeatingInputWidget",
            "FormField", "FormFieldsContainer", "CompoundFormField",
            "RepeatingFormField", "Label", "TextField", "PasswordField",
-           "HiddenField", "FileField", "Button", "SubmitButton", 
+           "HiddenField", "FileField", "Button", "SubmitButton",
            "ResetButton", "ImageButton", "CheckBox", "TextArea",
-           "SelectionField", "SingleSelectField", "MultipleSelectField", 
-           "RadioButtonList", "CheckBoxList", "FieldSet", 
-           "RepeatingFieldSet", "Form", "TableForm", "ListForm", 
+           "SelectionField", "SingleSelectField", "MultipleSelectField",
+           "RadioButtonList", "CheckBoxList", "FieldSet",
+           "RepeatingFieldSet", "Form", "TableForm", "ListForm",
            "WidgetsList"]
 
 #############################################################################
@@ -100,7 +100,7 @@
 def retrieve_params_by_path(params, path):
     if not path:
         return None
-    else: 
+    else:
         if not isinstance(path[0], tuple):
             path = adapt_path(path)
         for name, index in path:
@@ -145,11 +145,11 @@
 
         It accepts the following parameters (besides those listed at params):
 
-          name: 
+          name:
              Name of the input element. Will be the name of the variable
              the widget's input will be available at when submitted.
 
-          validator: 
+          validator:
              Formencode validator that will validate and coerce the input
              this widget generates.
         """
@@ -263,7 +263,7 @@
         widget instance or it's name, ``value`` is a dict containing the
         value for this compound widget."""
         path = path_from_item(item)
-        return retrieve_value_by_path(value, path) 
+        return retrieve_value_by_path(value, path)
 
     def params_for(self, item, **params):
         """Return the parameters for a child widget. ``item`` is the child
@@ -273,7 +273,7 @@
         return retrieve_params_by_path(params, path)
 
     def error_for(self, item, suppress_errors=False):
-        """Return's the Invalid exception associated to a child widget from 
+        """Return's the Invalid exception associated to a child widget from
         request local storage. ``item`` is the child widget instance or it's
         name."""
         if self.is_validated:
@@ -291,7 +291,7 @@
     def dictify_value(self, value):
         """Converts a value into a dict suitable for propagating values to
         child widgets. If value is a dict it will pass thorugh, if it other
-        kind of object, attributes which match child widgets' names will be 
+        kind of object, attributes which match child widgets' names will be
         tried to fetch."""
         if isinstance(value, dict):
             return value
@@ -363,7 +363,7 @@
         else:
             value = None
         path = path_from_item(item)
-        return retrieve_value_by_path(value, path) 
+        return retrieve_value_by_path(value, path)
 
     def params_for(self, item, **params):
         """Return the parameters for a child widget. ``item`` is the child
@@ -378,11 +378,11 @@
                     pass
         path = path_from_item(item)
         return retrieve_params_by_path(item_params, path)
-    
+
     def dictify_value(self, value):
-        """Converts a list of values into a list of dicts suitable for 
-        propagating values to child widgets. If value is a list of dicts it 
-        will pass thorugh, if it other kind of object, attributes which match 
+        """Converts a list of values into a list of dicts suitable for
+        propagating values to child widgets. If value is a list of dicts it
+        will pass thorugh, if it other kind of object, attributes which match
         child widgets' names will be
         tried to fetch."""
         return [super(RepeatingInputWidget, self).dictify_value(v)
@@ -397,10 +397,10 @@
     It accepts the following parameters (besides those listed at params):
 
     label
-       The label text that the container form/fieldset will generate for the 
+       The label text that the container form/fieldset will generate for the
        widget. If empty, the capitalized name will be used.
     help_text
-       The help text that the container form/fieldset will generate for the 
+       The help text that the container form/fieldset will generate for the
        widget.
     """
     _name = "widget"
@@ -499,7 +499,7 @@
            Returns the validation error the child named ``name`` generated.
            Again, ``name`` can also be a widget instance.
     """
-        
+
     member_widgets = ["fields", "hidden_fields"]
     fields = []
     hidden_fields = []
@@ -548,7 +548,7 @@
         visible_fields = []
         hidden_fields = []
         #XXX: Ugly hack, this badly needs a better fix. Note to meself:
-        #     CompoundFormField has no fields or hidden_fields member_widgets, 
+        #     CompoundFormField has no fields or hidden_fields member_widgets,
         #     related to [1736]'s refactoring.
         for field in d.get("fields", []) + d.get("hidden_fields", []):
             if field.name not in d["disabled_fields"]:
@@ -606,8 +606,8 @@
 
 class TextFieldDesc(CoreWD):
     name = "Text Field"
-    for_widget = TextField("your_name", 
-                           default="Your Name Here", 
+    for_widget = TextField("your_name",
+                           default="Your Name Here",
                            attrs=dict(size="30"))
 
 class PasswordField(FormField):
@@ -630,7 +630,7 @@
 
 class PasswordFieldDesc(CoreWD):
     name = "Password Field"
-    for_widget = PasswordField("your_secret", 
+    for_widget = PasswordField("your_secret",
                                default="Top Secret Password")
 
 class HiddenField(FormField):
@@ -783,13 +783,13 @@
 
 class CheckBoxDesc(CoreWD):
     for_widget = CheckBox(name="your_checkbox",
-                          attrs=dict(checked=True),
+                          default=True,
                           help_text="Just click me...")
     template = """
     <div xmlns:py="http://purl.org/kid/ns#";>
         ${for_widget.display()}
-        <label for="${for_widget.field_id}" 
-            py:content="for_widget.help_text" 
+        <label for="${for_widget.field_id}"
+            py:content="for_widget.help_text"
         />
     </div>
     """
@@ -847,7 +847,7 @@
         # as a whole.
         if self._multiple_selection and \
            not isinstance(self.validator, validators.ForEach):
-            self.validator = validators.MultipleSelection(self.validator)      
      
+            self.validator = validators.MultipleSelection(self.validator)
 
     def _guess_validator(self):
         """
@@ -959,9 +959,9 @@
 
 class SingleSelectFieldDesc(CoreWD):
     name = "Single Select Field"
-    for_widget = SingleSelectField("your_single_select_field", 
-                                   options=[(1, "Python"), 
-                                            (2, "Java"), 
+    for_widget = SingleSelectField("your_single_select_field",
+                                   options=[(1, "Python"),
+                                            (2, "Java"),
                                             (3, "Pascal"),
                                             (4, "Ruby")],
                                    default=2)
@@ -997,9 +997,9 @@
 
 class MultipleSelectFieldDesc(CoreWD):
     name = "Multiple Select Field"
-    for_widget = MultipleSelectField("your_multiple_select_field", 
-                                     options=[("a", "Python"), 
-                                              ("b", "Java"), 
+    for_widget = MultipleSelectField("your_multiple_select_field",
+                                     options=[("a", "Python"),
+                                              ("b", "Java"),
                                               ("c", "Pascal"),
                                               ("d", "Ruby")],
                                      default=["a","c","d"])
@@ -1029,9 +1029,9 @@
 
 class RadioButtonListDesc(CoreWD):
     name = "RadioButton List"
-    for_widget = RadioButtonList("your_radiobutton_list", 
-                                 options=[(1, "Python"), 
-                                          (2, "Java"), 
+    for_widget = RadioButtonList("your_radiobutton_list",
+                                 options=[(1, "Python"),
+                                          (2, "Java"),
                                           (3, "Pascal"),
                                           (4, "Ruby")],
                                  default=4)
@@ -1062,9 +1062,9 @@
 
 class CheckBoxListDesc(CoreWD):
     name = "CheckBox List"
-    for_widget = CheckBoxList("your_checkbox_list", 
-                              options=[(1, "Python"), 
-                                       (2, "Java"), 
+    for_widget = CheckBoxList("your_checkbox_list",
+                              options=[(1, "Python"),
+                                       (2, "Java"),
                                        (3, "Pascal"),
                                        (4, "Ruby")],
                               default=[1,4])
@@ -1076,8 +1076,8 @@
         id="${field_id}"
     >
         <legend py:if="legend" py:content="legend" />
-        <div py:for="field in hidden_fields" 
-            py:replace="field.display(value_for(field), **params_for(field))" 
+        <div py:for="field in hidden_fields"
+            py:replace="field.display(value_for(field), **params_for(field))"
         />
         <div py:for="field in fields">
             <label class="fieldlabel" for="${field.field_id}" 
py:content="field.label" />
@@ -1094,8 +1094,8 @@
 class FieldSetDesc(CoreWD):
     name = "FieldSet"
     for_widget = FieldSet("your_fieldset",
-                          legend="Range", 
-                          fields=[TextField(name="lower_limit", 
+                          legend="Range",
+                          fields=[TextField(name="lower_limit",
                                             label="Lower Limit"),
                                   TextField(name="upper_limit",
                                             label="Upper Limit")])
@@ -1108,8 +1108,8 @@
         id="${field_id}_${repetition}"
     >
         <legend py:if="legend" py:content="legend" />
-        <div py:for="field in hidden_fields" 
-            py:replace="field.display(value_for(field), **params_for(field))" 
+        <div py:for="field in hidden_fields"
+            py:replace="field.display(value_for(field), **params_for(field))"
         />
         <div py:for="field in fields">
             <label class="fieldlabel" for="${field.field_id}" 
py:content="field.label" />
@@ -1127,9 +1127,9 @@
 class RepeatingFieldSetDesc(CoreWD):
     name = "Repeating FieldSet"
     for_widget = RepeatingFieldSet("your_repeating_fieldset",
-                                   legend='Range', 
+                                   legend='Range',
                                    repetitions=3,
-                                   fields=[TextField(name="lower_limit", 
+                                   fields=[TextField(name="lower_limit",
                                                      label="Lower Limit"),
                                            TextField(name="upper_limit",
                                                      label="Upper Limit")])
@@ -1179,11 +1179,11 @@
         class="tableform"
         py:attrs="form_attrs"
     >
-        <div py:for="field in hidden_fields" 
-            py:replace="field.display(value_for(field), **params_for(field))" 
+        <div py:for="field in hidden_fields"
+            py:replace="field.display(value_for(field), **params_for(field))"
         />
         <table border="0" cellspacing="0" cellpadding="2" 
py:attrs="table_attrs">
-            <tr py:for="i, field in enumerate(fields)" 
+            <tr py:for="i, field in enumerate(fields)"
                 class="${i%2 and 'odd' or 'even'}"
             >
                 <th>
@@ -1238,11 +1238,11 @@
         class="listform"
         py:attrs="form_attrs"
     >
-        <div py:for="field in hidden_fields" 
-            py:replace="field.display(value_for(field), **params_for(field))" 
+        <div py:for="field in hidden_fields"
+            py:replace="field.display(value_for(field), **params_for(field))"
         />
         <ul py:attrs="list_attrs">
-            <li py:for="i, field in enumerate(fields)" 
+            <li py:for="i, field in enumerate(fields)"
                 class="${i%2 and 'odd' or 'even'}"
             >
                 <label class="fieldlabel" for="${field.field_id}" 
py:content="field.label" />

Modified: branches/1.1/turbogears/widgets/forms.py
==============================================================================
--- branches/1.1/turbogears/widgets/forms.py    (original)
+++ branches/1.1/turbogears/widgets/forms.py    Mon Jul 23 09:40:10 2007
@@ -12,11 +12,11 @@
 __all__ = ["InputWidget", "CompoundInputWidget", "RepeatingInputWidget",
            "FormField", "FormFieldsContainer", "CompoundFormField",
            "RepeatingFormField", "Label", "TextField", "PasswordField",
-           "HiddenField", "FileField", "Button", "SubmitButton", 
+           "HiddenField", "FileField", "Button", "SubmitButton",
            "ResetButton", "ImageButton", "CheckBox", "TextArea",
-           "SelectionField", "SingleSelectField", "MultipleSelectField", 
-           "RadioButtonList", "CheckBoxList", "FieldSet", 
-           "RepeatingFieldSet", "Form", "TableForm", "ListForm", 
+           "SelectionField", "SingleSelectField", "MultipleSelectField",
+           "RadioButtonList", "CheckBoxList", "FieldSet",
+           "RepeatingFieldSet", "Form", "TableForm", "ListForm",
            "WidgetsList"]
 
 #############################################################################
@@ -100,7 +100,7 @@
 def retrieve_params_by_path(params, path):
     if not path:
         return None
-    else: 
+    else:
         if not isinstance(path[0], tuple):
             path = adapt_path(path)
         for name, index in path:
@@ -145,11 +145,11 @@
 
         It accepts the following parameters (besides those listed at params):
 
-          name: 
+          name:
              Name of the input element. Will be the name of the variable
              the widget's input will be available at when submitted.
 
-          validator: 
+          validator:
              Formencode validator that will validate and coerce the input
              this widget generates.
         """
@@ -263,7 +263,7 @@
         widget instance or it's name, ``value`` is a dict containing the
         value for this compound widget."""
         path = path_from_item(item)
-        return retrieve_value_by_path(value, path) 
+        return retrieve_value_by_path(value, path)
 
     def params_for(self, item, **params):
         """Return the parameters for a child widget. ``item`` is the child
@@ -273,7 +273,7 @@
         return retrieve_params_by_path(params, path)
 
     def error_for(self, item, suppress_errors=False):
-        """Return's the Invalid exception associated to a child widget from 
+        """Return's the Invalid exception associated to a child widget from
         request local storage. ``item`` is the child widget instance or it's
         name."""
         if self.is_validated:
@@ -291,7 +291,7 @@
     def dictify_value(self, value):
         """Converts a value into a dict suitable for propagating values to
         child widgets. If value is a dict it will pass thorugh, if it other
-        kind of object, attributes which match child widgets' names will be 
+        kind of object, attributes which match child widgets' names will be
         tried to fetch."""
         if isinstance(value, dict):
             return value
@@ -363,7 +363,7 @@
         else:
             value = None
         path = path_from_item(item)
-        return retrieve_value_by_path(value, path) 
+        return retrieve_value_by_path(value, path)
 
     def params_for(self, item, **params):
         """Return the parameters for a child widget. ``item`` is the child
@@ -378,11 +378,11 @@
                     pass
         path = path_from_item(item)
         return retrieve_params_by_path(item_params, path)
-    
+
     def dictify_value(self, value):
-        """Converts a list of values into a list of dicts suitable for 
-        propagating values to child widgets. If value is a list of dicts it 
-        will pass thorugh, if it other kind of object, attributes which match 
+        """Converts a list of values into a list of dicts suitable for
+        propagating values to child widgets. If value is a list of dicts it
+        will pass thorugh, if it other kind of object, attributes which match
         child widgets' names will be
         tried to fetch."""
         return [super(RepeatingInputWidget, self).dictify_value(v)
@@ -397,10 +397,10 @@
     It accepts the following parameters (besides those listed at params):
 
     label
-       The label text that the container form/fieldset will generate for the 
+       The label text that the container form/fieldset will generate for the
        widget. If empty, the capitalized name will be used.
     help_text
-       The help text that the container form/fieldset will generate for the 
+       The help text that the container form/fieldset will generate for the
        widget.
     """
     _name = "widget"
@@ -499,7 +499,7 @@
            Returns the validation error the child named ``name`` generated.
            Again, ``name`` can also be a widget instance.
     """
-        
+
     member_widgets = ["fields", "hidden_fields"]
     fields = []
     hidden_fields = []
@@ -548,7 +548,7 @@
         visible_fields = []
         hidden_fields = []
         #XXX: Ugly hack, this badly needs a better fix. Note to meself:
-        #     CompoundFormField has no fields or hidden_fields member_widgets, 
+        #     CompoundFormField has no fields or hidden_fields member_widgets,
         #     related to [1736]'s refactoring.
         for field in d.get("fields", []) + d.get("hidden_fields", []):
             if field.name not in d["disabled_fields"]:
@@ -606,8 +606,8 @@
 
 class TextFieldDesc(CoreWD):
     name = "Text Field"
-    for_widget = TextField("your_name", 
-                           default="Your Name Here", 
+    for_widget = TextField("your_name",
+                           default="Your Name Here",
                            attrs=dict(size="30"))
 
 class PasswordField(FormField):
@@ -630,7 +630,7 @@
 
 class PasswordFieldDesc(CoreWD):
     name = "Password Field"
-    for_widget = PasswordField("your_secret", 
+    for_widget = PasswordField("your_secret",
                                default="Top Secret Password")
 
 class HiddenField(FormField):
@@ -783,13 +783,13 @@
 
 class CheckBoxDesc(CoreWD):
     for_widget = CheckBox(name="your_checkbox",
-                          attrs=dict(checked=True),
+                          default=True,
                           help_text="Just click me...")
     template = """
     <div xmlns:py="http://purl.org/kid/ns#";>
         ${for_widget.display()}
-        <label for="${for_widget.field_id}" 
-            py:content="for_widget.help_text" 
+        <label for="${for_widget.field_id}"
+            py:content="for_widget.help_text"
         />
     </div>
     """
@@ -847,7 +847,7 @@
         # as a whole.
         if self._multiple_selection and \
            not isinstance(self.validator, validators.ForEach):
-            self.validator = validators.MultipleSelection(self.validator)      
      
+            self.validator = validators.MultipleSelection(self.validator)
 
     def _guess_validator(self):
         """
@@ -959,9 +959,9 @@
 
 class SingleSelectFieldDesc(CoreWD):
     name = "Single Select Field"
-    for_widget = SingleSelectField("your_single_select_field", 
-                                   options=[(1, "Python"), 
-                                            (2, "Java"), 
+    for_widget = SingleSelectField("your_single_select_field",
+                                   options=[(1, "Python"),
+                                            (2, "Java"),
                                             (3, "Pascal"),
                                             (4, "Ruby")],
                                    default=2)
@@ -997,9 +997,9 @@
 
 class MultipleSelectFieldDesc(CoreWD):
     name = "Multiple Select Field"
-    for_widget = MultipleSelectField("your_multiple_select_field", 
-                                     options=[("a", "Python"), 
-                                              ("b", "Java"), 
+    for_widget = MultipleSelectField("your_multiple_select_field",
+                                     options=[("a", "Python"),
+                                              ("b", "Java"),
                                               ("c", "Pascal"),
                                               ("d", "Ruby")],
                                      default=["a","c","d"])
@@ -1029,9 +1029,9 @@
 
 class RadioButtonListDesc(CoreWD):
     name = "RadioButton List"
-    for_widget = RadioButtonList("your_radiobutton_list", 
-                                 options=[(1, "Python"), 
-                                          (2, "Java"), 
+    for_widget = RadioButtonList("your_radiobutton_list",
+                                 options=[(1, "Python"),
+                                          (2, "Java"),
                                           (3, "Pascal"),
                                           (4, "Ruby")],
                                  default=4)
@@ -1062,9 +1062,9 @@
 
 class CheckBoxListDesc(CoreWD):
     name = "CheckBox List"
-    for_widget = CheckBoxList("your_checkbox_list", 
-                              options=[(1, "Python"), 
-                                       (2, "Java"), 
+    for_widget = CheckBoxList("your_checkbox_list",
+                              options=[(1, "Python"),
+                                       (2, "Java"),
                                        (3, "Pascal"),
                                        (4, "Ruby")],
                               default=[1,4])
@@ -1076,8 +1076,8 @@
         id="${field_id}"
     >
         <legend py:if="legend" py:content="legend" />
-        <div py:for="field in hidden_fields" 
-            py:replace="field.display(value_for(field), **params_for(field))" 
+        <div py:for="field in hidden_fields"
+            py:replace="field.display(value_for(field), **params_for(field))"
         />
         <div py:for="field in fields">
             <label class="fieldlabel" for="${field.field_id}" 
py:content="field.label" />
@@ -1094,8 +1094,8 @@
 class FieldSetDesc(CoreWD):
     name = "FieldSet"
     for_widget = FieldSet("your_fieldset",
-                          legend="Range", 
-                          fields=[TextField(name="lower_limit", 
+                          legend="Range",
+                          fields=[TextField(name="lower_limit",
                                             label="Lower Limit"),
                                   TextField(name="upper_limit",
                                             label="Upper Limit")])
@@ -1108,8 +1108,8 @@
         id="${field_id}_${repetition}"
     >
         <legend py:if="legend" py:content="legend" />
-        <div py:for="field in hidden_fields" 
-            py:replace="field.display(value_for(field), **params_for(field))" 
+        <div py:for="field in hidden_fields"
+            py:replace="field.display(value_for(field), **params_for(field))"
         />
         <div py:for="field in fields">
             <label class="fieldlabel" for="${field.field_id}" 
py:content="field.label" />
@@ -1127,9 +1127,9 @@
 class RepeatingFieldSetDesc(CoreWD):
     name = "Repeating FieldSet"
     for_widget = RepeatingFieldSet("your_repeating_fieldset",
-                                   legend='Range', 
+                                   legend='Range',
                                    repetitions=3,
-                                   fields=[TextField(name="lower_limit", 
+                                   fields=[TextField(name="lower_limit",
                                                      label="Lower Limit"),
                                            TextField(name="upper_limit",
                                                      label="Upper Limit")])
@@ -1179,11 +1179,11 @@
         class="tableform"
         py:attrs="form_attrs"
     >
-        <div py:for="field in hidden_fields" 
-            py:replace="field.display(value_for(field), **params_for(field))" 
+        <div py:for="field in hidden_fields"
+            py:replace="field.display(value_for(field), **params_for(field))"
         />
         <table border="0" cellspacing="0" cellpadding="2" 
py:attrs="table_attrs">
-            <tr py:for="i, field in enumerate(fields)" 
+            <tr py:for="i, field in enumerate(fields)"
                 class="${i%2 and 'odd' or 'even'}"
             >
                 <th>
@@ -1238,11 +1238,11 @@
         class="listform"
         py:attrs="form_attrs"
     >
-        <div py:for="field in hidden_fields" 
-            py:replace="field.display(value_for(field), **params_for(field))" 
+        <div py:for="field in hidden_fields"
+            py:replace="field.display(value_for(field), **params_for(field))"
         />
         <ul py:attrs="list_attrs">
-            <li py:for="i, field in enumerate(fields)" 
+            <li py:for="i, field in enumerate(fields)"
                 class="${i%2 and 'odd' or 'even'}"
             >
                 <label class="fieldlabel" for="${field.field_id}" 
py:content="field.label" />

Reply via email to