[Checkins] SVN: zc.table/trunk/src/zc/table/ commit test revision showing how to use Choice fields.

Gary Poster gary at zope.com
Thu Jan 25 20:50:19 EST 2007


Log message for revision 72232:
  commit test revision showing how to use Choice fields.

Changed:
  U   zc.table/trunk/src/zc/table/fieldcolumn.py
  U   zc.table/trunk/src/zc/table/fieldcolumn.txt
  U   zc.table/trunk/src/zc/table/tests.py

-=-
Modified: zc.table/trunk/src/zc/table/fieldcolumn.py
===================================================================
--- zc.table/trunk/src/zc/table/fieldcolumn.py	2007-01-25 21:51:56 UTC (rev 72231)
+++ zc.table/trunk/src/zc/table/fieldcolumn.py	2007-01-26 01:50:18 UTC (rev 72232)
@@ -68,8 +68,6 @@
 
 class FieldColumn(BaseColumn):
     """Column that supports field/widget update
-
-    Note that fields are only bound if bind == True.
     """
 
     __slots__ = ('title', 'name', 'field') # to emphasize that this should not

Modified: zc.table/trunk/src/zc/table/fieldcolumn.txt
===================================================================
--- zc.table/trunk/src/zc/table/fieldcolumn.txt	2007-01-25 21:51:56 UTC (rev 72231)
+++ zc.table/trunk/src/zc/table/fieldcolumn.txt	2007-01-26 01:50:18 UTC (rev 72232)
@@ -55,19 +55,24 @@
     ...     email = schema.TextLine(
     ...             title=u'Email Address',
     ...             constraint=re.compile('\w+@\w+([.]\w+)+$').match)
+    ...     salutation = schema.Choice( 
+    ...		       title=u'Salutation',
+    ...		       values = ['Mr','Ms'],
+    ...		       )
 
     >>> class Contact:
     ...     interface.implements(IContact)
-    ...     def __init__(self, id, name, email):
+    ...     def __init__(self, id, name, email, salutation):
     ...         self.id = id
     ...         self.name = name
     ...         self.email = email
+    ...         self.salutation = salutation
 
     >>> contacts = (
-    ...     Contact('1', 'Bob Smith', 'bob at zope.com'),
-    ...     Contact('2', 'Sally Baker', 'sally at zope.com'),
-    ...     Contact('3', 'Jethro Tul', 'jethro at zope.com'),
-    ...     Contact('4', 'Joe Walsh', 'joe at zope.com'),
+    ...     Contact('1', 'Bob Smith', 'bob at zope.com', 'Mr'),
+    ...     Contact('2', 'Sally Baker', 'sally at zope.com', 'Ms'),
+    ...     Contact('3', 'Jethro Tul', 'jethro at zope.com', 'Mr'),
+    ...     Contact('4', 'Joe Walsh', 'joe at zope.com', 'Mr'),
     ...     )
 
 We'll define columns that allow us to display and edit name and
@@ -77,8 +82,15 @@
     >>> class ContactColumn(fieldcolumn.FieldColumn):
     ...     def getId(self, item, formatter):
     ...         return fieldcolumn.toSafe(item.id)
+    ...
+    >>> class BindingContactColumn(ContactColumn):
+    ...     def getFieldContext(self, item, formatter):
+    ...         return item
+    ...
     >>> columns = (ContactColumn(IContact["name"]),
-    ...            ContactColumn(IContact["email"]))
+    ...            ContactColumn(IContact["email"]),
+    ...	           BindingContactColumn(IContact["salutation"])
+    ...            )
 
 Now, with this, we can create a table with input widgets.  The columns don't 
 need a context other than the items themselves, so we ignore that part of the
@@ -100,6 +112,9 @@
         <th>
           Email Address
         </th>
+        <th>
+          Salutation
+        </th>
       </tr>
     </thead>
     <tbody>
@@ -112,6 +127,19 @@
           <input class="textType" id="test.1.email" name="test.1.email"
                  size="20" type="text" value="bob at zope.com"  />
         </td>
+        <td>
+          <div>
+            <div class="value">
+              <select id="test.1.salutation" name="test.1.salutation"
+                      size="1" >
+                <option selected="selected" value="Mr">Mr</option>
+                <option value="Ms">Ms</option>
+              </select>
+            </div>
+            <input name="test.1.salutation-empty-marker" type="hidden"
+                   value="1" />
+          </div>
+        </td>
       </tr>
       <tr>
         <td>
@@ -122,6 +150,19 @@
           <input class="textType" id="test.2.email" name="test.2.email"
                  size="20" type="text" value="sally at zope.com"  />
         </td>
+        <td>
+          <div>
+            <div class="value">
+              <select id="test.2.salutation" name="test.2.salutation"
+                      size="1" >
+                <option value="Mr">Mr</option>
+                <option selected="selected" value="Ms">Ms</option>
+              </select>
+            </div>
+            <input name="test.2.salutation-empty-marker" type="hidden"
+                   value="1" />
+          </div>
+        </td>
       </tr>
       <tr>
         <td>
@@ -132,6 +173,19 @@
           <input class="textType" id="test.3.email" name="test.3.email"
                  size="20" type="text" value="jethro at zope.com"  />
         </td>
+        <td>
+          <div>
+            <div class="value">
+              <select id="test.3.salutation" name="test.3.salutation"
+                      size="1" >
+                <option selected="selected" value="Mr">Mr</option>
+                <option value="Ms">Ms</option>
+              </select>
+            </div>
+            <input name="test.3.salutation-empty-marker" type="hidden"
+                   value="1" />
+          </div>
+        </td>
       </tr>
       <tr>
         <td>
@@ -142,6 +196,19 @@
           <input class="textType" id="test.4.email" name="test.4.email"
                  size="20" type="text" value="joe at zope.com"  />
         </td>
+        <td>
+          <div>
+            <div class="value">
+              <select id="test.4.salutation" name="test.4.salutation"
+                      size="1" >
+                <option selected="selected" value="Mr">Mr</option>
+                <option value="Ms">Ms</option>
+              </select>
+            </div>
+            <input name="test.4.salutation-empty-marker" type="hidden"
+                   value="1" />
+          </div>
+        </td>
       </tr>
     </tbody>
     </table>
@@ -162,6 +229,9 @@
         <th>
           Email Address
         </th>
+        <th>
+          Salutation
+        </th>
       </tr>
     </thead>
     <tbody>
@@ -174,6 +244,19 @@
           <input class="textType" id="test.1.email" name="test.1.email"
                  size="20" type="text" value="bob at zope.com"  />
         </td>
+        <td>
+          <div>
+            <div class="value">
+              <select id="test.1.salutation" name="test.1.salutation"
+                      size="1" >
+                <option selected="selected" value="Mr">Mr</option>
+                <option value="Ms">Ms</option>
+              </select>
+            </div>
+            <input name="test.1.salutation-empty-marker" type="hidden"
+                   value="1" />
+          </div>
+        </td>
       </tr>
       <tr>
         <td>
@@ -184,6 +267,19 @@
           <input class="textType" id="test.2.email" name="test.2.email"
                  size="20" type="text" value="sally at zope.com"  />
         </td>
+        <td>
+          <div>
+            <div class="value">
+              <select id="test.2.salutation" name="test.2.salutation"
+                      size="1" >
+                <option value="Mr">Mr</option>
+                <option selected="selected" value="Ms">Ms</option>
+              </select>
+            </div>
+            <input name="test.2.salutation-empty-marker" type="hidden"
+                   value="1" />
+          </div>
+        </td>
       </tr>
       <tr>
         <td>
@@ -194,6 +290,19 @@
           <input class="textType" id="test.3.email" name="test.3.email"
                  size="20" type="text" value="jethro at zope.com"  />
         </td>
+        <td>
+          <div>
+            <div class="value">
+              <select id="test.3.salutation" name="test.3.salutation"
+                      size="1" >
+                <option selected="selected" value="Mr">Mr</option>
+                <option value="Ms">Ms</option>
+              </select>
+            </div>
+            <input name="test.3.salutation-empty-marker" type="hidden"
+                   value="1" />
+          </div>
+        </td>
       </tr>
       <tr>
         <td>
@@ -204,6 +313,19 @@
           <input class="textType" id="test.4.email" name="test.4.email"
                  size="20" type="text" value="walsh at zope.com"  />
         </td>
+        <td>
+          <div>
+            <div class="value">
+              <select id="test.4.salutation" name="test.4.salutation"
+                      size="1" >
+                <option selected="selected" value="Mr">Mr</option>
+                <option value="Ms">Ms</option>
+              </select>
+            </div>
+            <input name="test.4.salutation-empty-marker" type="hidden"
+                   value="1" />
+          </div>
+        </td>
       </tr>
     </tbody>
     </table>

Modified: zc.table/trunk/src/zc/table/tests.py
===================================================================
--- zc.table/trunk/src/zc/table/tests.py	2007-01-25 21:51:56 UTC (rev 72231)
+++ zc.table/trunk/src/zc/table/tests.py	2007-01-26 01:50:18 UTC (rev 72232)
@@ -37,6 +37,32 @@
          ),
         zope.app.form.interfaces.IInputWidget)
 
+def fieldColumnSetUp(test):
+    columnSetUp(test)
+    component.provideAdapter(
+        zope.app.form.browser.ChoiceDisplayWidget,
+        (zope.schema.interfaces.IChoice,
+         zope.publisher.interfaces.browser.IBrowserRequest),
+        zope.app.form.interfaces.IDisplayWidget)
+    component.provideAdapter(
+        zope.app.form.browser.ChoiceInputWidget,
+        (zope.schema.interfaces.IChoice,
+         zope.publisher.interfaces.browser.IBrowserRequest),
+        zope.app.form.interfaces.IInputWidget)
+    component.provideAdapter(
+        zope.app.form.browser.DropdownWidget,
+        (zope.schema.interfaces.IChoice,
+         zope.schema.interfaces.IVocabularyTokenized,
+         zope.publisher.interfaces.browser.IBrowserRequest),
+        zope.app.form.interfaces.IInputWidget)
+    component.provideAdapter(
+        zope.app.form.browser.ChoiceDisplayWidget,
+        (zope.schema.interfaces.IChoice,
+         zope.schema.interfaces.IVocabularyTokenized,
+         zope.publisher.interfaces.browser.IBrowserRequest),
+        zope.app.form.interfaces.IDisplayWidget)
+    
+
 def test_suite():
     from zope.testing import doctest
     return unittest.TestSuite((
@@ -50,7 +76,7 @@
             ),
         doctest.DocFileSuite(
             'fieldcolumn.txt',
-            setUp = columnSetUp, tearDown=placelesssetup.tearDown,
+            setUp = fieldColumnSetUp, tearDown=placelesssetup.tearDown,
             optionflags=doctest.NORMALIZE_WHITESPACE+doctest.ELLIPSIS,
             ),
         ))



More information about the Checkins mailing list