[Zope3-Users] Using formlib schema.Choice with zc.table FieldColumn

ksmith93940-dev at yahoo.com ksmith93940-dev at yahoo.com
Thu Jan 25 18:09:43 EST 2007


Whoa, really bad line breaks, here is the pastbin link

http://zope3.pastebin.com/867518

David, zc.table makes rendering html tables more
programmatic.


--- ksmith93940-dev at yahoo.com wrote:

> Thanks for the direction, Gary. :) 
> 
> Getting a Choice field working in doctests was quite
> a
> challenge. It now fails as only as a zc.table
> FieldColumn. I'm including the relevant doctests and
> tests.py
> 
> I apologize in advance for the verbose post. :)
> 
> Kevin Smith
> 
> 
> 
> 
> File
>
"/root/temp/zc.table-0.6/src/zc/table/fieldcolumn.txt",
> line 131, in fieldcolumn.txt
> Failed example:
>     print formatter()
> Exception raised:
>     Traceback (most recent call last):
>       File
>
"/root/temp/zc.table-0.6/eggs/zope.testing-3.0-py2.4.egg/zope/testing/doctest.py",
> line 1348, in __run
>         compileflags, 1) in test.globs
>       File "<doctest fieldcolumn.txt[19]>", line 1,
> in
> ?
>         print formatter()
>       File
> "/root/temp/zc.table-0.6/src/zc/table/table.py",
> line
> 66, in __call__
>         return '\n<table%s>\n%s</table>\n%s' % (
>       File
> "/root/temp/zc.table-0.6/src/zc/table/table.py",
> line
> 75, in renderContents
>         return '  <thead%s>\n%s  </thead>\n 
> <tbody>\n%s  </tbody>\n' % (
>       File
> "/root/temp/zc.table-0.6/src/zc/table/table.py",
> line
> 98, in renderRows
>         return ''.join([self.renderRow(item) for
> item
> in self.getItems()])
>       File
> "/root/temp/zc.table-0.6/src/zc/table/table.py",
> line
> 106, in renderRow
>         return '  <tr%s>\n%s  </tr>\n' % (
>       File
> "/root/temp/zc.table-0.6/src/zc/table/table.py",
> line
> 110, in renderCells
>         return ''.join(
>       File
> "/root/temp/zc.table-0.6/src/zc/table/table.py",
> line
> 114, in renderCell
>         return '    <td%s>\n      %s\n    </td>\n' %
> (
>       File
> "/root/temp/zc.table-0.6/src/zc/table/table.py",
> line
> 121, in getCell
>         return column.renderCell(item, self)
>       File
>
"/root/temp/zc.table-0.6/src/zc/table/fieldcolumn.py",
> line 162, in renderCell
>         return self.getRenderWidget(
>       File
>
"/root/temp/zc.table-0.6/src/zc/table/fieldcolumn.py",
> line 114, in getRenderWidget
>         widget = self.getInputWidget(item,
> formatter)
>       File
>
"/root/temp/zc.table-0.6/src/zc/table/fieldcolumn.py",
> line 105, in getInputWidget
>         widget = component.getMultiAdapter((field,
> request), iface)
>       File
>
"/root/temp/zc.table-0.6/parts/zope3/src/zope/component/_api.py",
> line 101, in getMultiAdapter
>         adapter = queryMultiAdapter(objects,
> interface, name, context=context)
>       File
>
"/root/temp/zc.table-0.6/parts/zope3/src/zope/component/_api.py",
> line 114, in queryMultiAdapter
>         return
> sitemanager.queryMultiAdapter(objects,
> interface, name, default)
>       File
>
"/root/temp/zc.table-0.6/parts/zope3/src/zope/component/registry.py",
> line 206, in queryMultiAdapter
>         return self.adapters.queryMultiAdapter(
>       File
>
"/root/temp/zc.table-0.6/parts/zope3/src/zope/interface/adapter.py",
> line 482, in queryMultiAdapter
>         result = factory(*objects)
>       File
>
"/root/temp/zc.table-0.6/parts/zope3/src/zope/app/form/browser/itemswidgets.py",
> line 44, in ChoiceInputWidget
>         IInputWidget)
>       File
>
"/root/temp/zc.table-0.6/parts/zope3/src/zope/component/_api.py",
> line 101, in getMultiAdapter
>         adapter = queryMultiAdapter(objects,
> interface, name, context=context)
>       File
>
"/root/temp/zc.table-0.6/parts/zope3/src/zope/component/_api.py",
> line 114, in queryMultiAdapter
>         return
> sitemanager.queryMultiAdapter(objects,
> interface, name, default)
>       File
>
"/root/temp/zc.table-0.6/parts/zope3/src/zope/component/registry.py",
> line 206, in queryMultiAdapter
>         return self.adapters.queryMultiAdapter(
>       File
>
"/root/temp/zc.table-0.6/parts/zope3/src/zope/interface/adapter.py",
> line 482, in queryMultiAdapter
>         result = factory(*objects)
>       File
>
"/root/temp/zc.table-0.6/parts/zope3/src/zope/app/form/browser/itemswidgets.py",
> line 315, in __init__
>         super(ItemsEditWidgetBase,
> self).__init__(field, vocabulary, request)
>       File
>
"/root/temp/zc.table-0.6/parts/zope3/src/zope/app/form/browser/itemswidgets.py",
> line 83, in __init__
>         assert field.context is not None
>     AssertionError
> 
> 
> 
> 
> == fieldcolumn.txt ==
> 
>    
>     >>> import re
>     >>> from zope import schema, interface
>     >>> class IContact(interface.Interface):
>     ...     name = schema.TextLine(title=u'Name')
>     ...     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,
> salutation):
>     ...         self.id = id
>     ...         self.name = name
>     ...         self.email = email
>     ...         self.salutation = salutation
> 
>     >>> contacts = (
>     ...     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'),
>     ...     )
> 
>     >>> from zope.formlib import form
> 
> 
> 
>     >>> class MyForm(form.EditForm):
>     ...	    form_fields = form.Fields( IContact )
> 
> Sanity test
> 
>     >>> from zope.publisher.browser import
> TestRequest
>     >>> request = TestRequest()
>     >>> myform = MyForm(contacts[0], request)
>     >>> print myform()
>     Name
>     <input class="textType" id="form.name"
> name="form.name" size="20" type="text" value="Bob
> Smith"  />
>     Email Address
>     <input class="textType" id="form.email"
> name="form.email" size="20" type="text"
> value="bob at zope.com"  />
>     Salutation
>     <div>
> 
=== message truncated ===



More information about the Zope3-users mailing list