[Zope3-Users] broken formlib - form.txt example

Vinny vinny-mail-01+zope3users at palaceofretention.ca
Tue Feb 6 20:40:10 EST 2007


Hello,

Platform details:

# pkg_info | grep zope
zope-3.3.0          An object-based web application platform
# uname -a
FreeBSD the.palaceofretention.ca 6.2-RELEASE #1:
# python
Python 2.4.3 (#2, Dec 26 2006, 16:13:56)
[GCC 3.4.4 [FreeBSD] 20050518] on freebsd6

Using IDLE 1.1.3

Using instructions from:
/usr/local/www/Zope3/lib/python/zope/formlib/form.txt

With code straight out of it typed into the IDLE editor, saved
as form.py and run using the F5 command:

=================== 8< ========
from zope import interface, schema
class IOrder(interface.Interface):
    identifier = schema.Int(title=u"Identifier", readonly=True)
    name = schema.TextLine(title=u"Name")
    min_size = schema.Float(title=u"Minimum size")
    max_size = schema.Float(title=u"Maximum size")
    now = schema.Datetime(title=u"Now", readonly=True)

from zope.formlib import form
class MyForm:
    form_fields = form.Fields(IOrder)

#This sets up a set of form fields from the interface, IOrder.

print len(MyForm.form_fields)

print [w.__name__ for w in MyForm.form_fields]

class MyForm:
    form_fields = form.Fields(IOrder, omit_readonly=True)

    def __init__(self, context, request):
        self.context, self.request = context, request

    def __call__(self, ignore_request=False):
        widgets = form.setUpWidgets(
            self.form_fields, 'form', self.context, self.request,
            ignore_request=ignore_request)
        return '\n'.join([w() for w in widgets])

from zope.publisher.browser import TestRequest
request = TestRequest()
print MyForm(None, request)() # doctest: +NORMALIZE_WHITESPACE

Saving and running this gives: 

>>> =================== RESTART ========================
>>> 
5
['identifier', 'name', 'min_size', 'max_size', 'now']

Traceback (most recent call last):
  File "/usr/local/www/Zope3/mv/lib/python/hello/form.py", line 33, in
-toplevel-
    print MyForm(None, request)() # doctest: +NORMALIZE_WHITESPACE
  File "/usr/local/www/Zope3/mv/lib/python/hello/form.py", line 28, in
__call__
    ignore_request=ignore_request)
  File "/usr/local/www/Zope3/lib/python/zope/formlib/form.py", line
256, in setUpWidgets
    IInputWidget)
  File "/usr/local/www/Zope3/lib/python/zope/component/_api.py", line
103, in getMultiAdapter
    raise ComponentLookupError(objects, interface, name)
ComponentLookupError: ((<zope.schema._bootstrapfields.TextLine object
at 0x8cf53cc>, <zope.publisher.browser.TestRequest instance
URL=http://127.0.0.1>), <InterfaceClass
zope.app.form.interfaces.IInputWidget>, u'')


Sigh.  Am I jinxed?  I've been trying to learn zope 3 for six
months now.  All I want is to be able to make a form from an
interface and display the dang thing.  Is that too much to
ask?  /rant

Does anyone know what's going wrong?  Do I need to upgrade
anything?

Thanks in advance.

Vinny



More information about the Zope3-users mailing list