[Zope-dev] OrderedMultiSelectWidget in Zope2: context weirdness?
Marius Gedminas
mgedmin at b4net.lt
Fri May 9 06:40:18 EDT 2008
On Thu, May 08, 2008 at 01:39:41PM -0400, Josh Johnson (jjmojojjmojo) wrote:
> I'm looking at the code for OrderedMultiSelectWidget, in
> zope.app.form.browser.itemswidgets (line 535).
>
> This code doesn't make sense to me:
>
> if hasattr(self.context.context, self.context.__name__):
> available_values = self.context.get(self.context.context)
self is a widget.
self.context is a field.
self.context.context is whatever the field was bound to.
This code works fine in an *edit* form, where all fields are bound to the
object you're editing. It won't work in any other kind of form where
you may want to specify the initial values yourself (with
setUpDataWidgets or widget.setRenderedValue). It's possible that the
hasattr check was intended to make the other kinds of forms appear to
work, until you stumbled upon an unfortunate name clash.
I don't know how to fix it, though.
> else:
> available_values = []
>
> From what I can tell, this code is grabbing anything on the current
> content/view that's named the same as the name of the vocabulary
> provider. This bit me earlier with this error:
..
> Module zope.app.form.browser.itemswidgets, line 547, in choices
> TypeError: iterable argument required
>
> I had a named utility that was mapped to a function called 'activities'
> which provides IVocabularyFactory. I had a browser form page that had a
> field in it that used that named utility. The form class had a method on
> it called 'activities'. Through some pdb digging, I was able to figure
> out that it was grabbing the view method and not the function. It makes
> sense looking at the code, but why would it work that way? Am I looking
> at this wrong, or is this a bug?
>
> My setup :
> Plone 3.0.6 (according to Plone control pannel.. it's supposed to be 3.1.1)
> CMF 2.1.1
> Zope (Zope 2.10.5-final, python 2.4.3, linux2)
> Python 2.4.3 (#2, Mar 7 2008, 01:58:20) [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)]
> PIL 1.1.5
> Five 1.5.6
>
> I can put together some example code to reproduce the issue, if necessary.
I think a reproducible testcase attached to a bug in
http://bugs.launcpad.net/zope3 could help a bit.
Marius Gedminas
--
Never be afraid to tell the world who you are.
-- Anonymous
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20080509/ec54e0ff/attachment-0001.bin
More information about the Zope-Dev
mailing list