[Zope3-dev] Re: Poll example for ObjectWidget
Peter Mayne
PeterMayne at ap.spherion.com
Thu Sep 30 21:35:14 EDT 2004
I've been trying to figure out why the Poll example in
zope/app/form/browser/widgets.txt doesn't work.
The zope.app.form.CustomWidgetFactory class (which is used in the custom
views) creates a widget as follows:
def __call__(self, context, request):
args = (context, request) + self.args
instance = self._widget_factory(*args)
for item in self.kw.items():
setattr(instance, item[0], item[1])
return instance
The SequenceWidget class has the following:
def __init__(self, context, value_type, request, subwidget=None):
super(SequenceWidget, self).__init__(context, request)
self.subwidget = None
The initializer has the extra parameter value_type between context and
request, so the arguments that the factory builds cannot match
__init__(), hence the error:
File "/opt/ZopeX3-3.0.0/lib/python/zope/app/form/__init__.py", line
92, in __call__
instance = self._widget_factory(*args)
TypeError: __init__() takes at least 4 arguments (3 given)
when attempting to add a Poll object.
Removing the value_type parameter from SequenceWidget.__init__() makes
Poll work fine, and since value_type isn't used anyway...
Alternatively, changing the def to:
def __init__(self, context, request, value_type=None, subwidget=None):
works too.
(Needless to say, this breaks the tests for SequenceWidget because they
all pass the value_type argument, but removing the now extraneous
TextLine() argument from each test widget creation fixes that.)
Presumably all widgets should conform to the
def __init__(self, context, request, ...):
style to match the CustomWidgetFactory; there's no documentation for
CustomWidgetFactory or IViewFactory that says it only works for a subset
of widgets. However (for instance), ItemDisplayWidget inherits from
ItemsWidgetBase, which has
def __init__(self, field, vocabulary, request):
which would have to be
def __init__(self, field, request, vocabulary):
to be able to be created by CustomWidgetFactory.
So, exactly how confused am I? :-) I've read
zope/app/form/browser/README.txt, and I'm none the wiser as to what
should be happening here.
PJDM
--
Peter Mayne
Spherion Technology Solutions
Canberra, ACT, Australia
"You're given the form, but you have to write the sonnet yourself.
What you say is completely up to you." - Mrs. Whatsit
More information about the Zope3-dev
mailing list