diff --git a/src/zc/table/fieldcolumn.py b/src/zc/table/fieldcolumn.py index cbec3e3..6d09af7 100644 --- a/src/zc/table/fieldcolumn.py +++ b/src/zc/table/fieldcolumn.py @@ -68,8 +68,6 @@ def getId(self, item, formatter): 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 diff --git a/src/zc/table/fieldcolumn.txt b/src/zc/table/fieldcolumn.txt index 8c4cacf..84c1151 100644 --- a/src/zc/table/fieldcolumn.txt +++ b/src/zc/table/fieldcolumn.txt @@ -55,19 +55,24 @@ with names and email addresses: ... 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@zope.com'), - ... Contact('2', 'Sally Baker', 'sally@zope.com'), - ... Contact('3', 'Jethro Tul', 'jethro@zope.com'), - ... Contact('4', 'Joe Walsh', 'joe@zope.com'), + ... Contact('1', 'Bob Smith', 'bob@zope.com', 'Mr'), + ... Contact('2', 'Sally Baker', 'sally@zope.com', 'Ms'), + ... Contact('3', 'Jethro Tul', 'jethro@zope.com', 'Mr'), + ... Contact('4', 'Joe Walsh', 'joe@zope.com', 'Mr'), ... ) We'll define columns that allow us to display and edit name and @@ -77,8 +82,15 @@ email addresses. >>> 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 @@ table formatter instantiation: Email Address + + Salutation + @@ -112,6 +127,19 @@ table formatter instantiation: + +
+
+ +
+ +
+ @@ -122,6 +150,19 @@ table formatter instantiation: + +
+
+ +
+ +
+ @@ -132,6 +173,19 @@ table formatter instantiation: + +
+
+ +
+ +
+ @@ -142,6 +196,19 @@ table formatter instantiation: + +
+
+ +
+ +
+ @@ -162,6 +229,9 @@ If the request has input for a value, then this will override item data: Email Address + + Salutation + @@ -174,6 +244,19 @@ If the request has input for a value, then this will override item data: + +
+
+ +
+ +
+ @@ -184,6 +267,19 @@ If the request has input for a value, then this will override item data: + +
+
+ +
+ +
+ @@ -194,6 +290,19 @@ If the request has input for a value, then this will override item data: + +
+
+ +
+ +
+ @@ -204,6 +313,19 @@ If the request has input for a value, then this will override item data: + +
+
+ +
+ +
+ diff --git a/src/zc/table/tests.py b/src/zc/table/tests.py index de9aeb1..97012e0 100644 --- a/src/zc/table/tests.py +++ b/src/zc/table/tests.py @@ -37,6 +37,32 @@ def columnSetUp(test): ), 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 @@ def test_suite(): ), doctest.DocFileSuite( 'fieldcolumn.txt', - setUp = columnSetUp, tearDown=placelesssetup.tearDown, + setUp = fieldColumnSetUp, tearDown=placelesssetup.tearDown, optionflags=doctest.NORMALIZE_WHITESPACE+doctest.ELLIPSIS, ), ))