Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: Dev

OrderedMultiSelectWidget in Zope2: context weirdness?

 

 

Zope dev RSS feed   Index | Next | Previous | View Threaded


joshjohnson.cpc at gmail

May 8, 2008, 10:39 AM

Post #1 of 2 (53 views)
Permalink
OrderedMultiSelectWidget in Zope2: context weirdness?

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)
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:

Traceback (innermost last):
Module ZPublisher.Publish, line 119, in publish
Module ZPublisher.mapply, line 88, in mapply
Module ZPublisher.Publish, line 42, in call_object
Module zope.formlib.form, line 770, in __call__
Module zope.formlib.form, line 764, in render
Module plone.app.form._named, line 26, in __call__
Module Shared.DC.Scripts.Bindings, line 313, in __call__
Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec
Module Products.PageTemplates.PageTemplateFile, line 129, in _exec
Module Products.PageTemplates.PageTemplate, line 89, in pt_render
Module zope.pagetemplate.pagetemplate, line 117, in pt_render
Module zope.tal.talinterpreter, line 271, in __call__
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 891, in do_useMacro
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 536, in do_optTag_tal
Module zope.tal.talinterpreter, line 521, in do_optTag
Module zope.tal.talinterpreter, line 516, in no_tag
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 891, in do_useMacro
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 536, in do_optTag_tal
Module zope.tal.talinterpreter, line 521, in do_optTag
Module zope.tal.talinterpreter, line 516, in no_tag
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 957, in do_defineSlot
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 536, in do_optTag_tal
Module zope.tal.talinterpreter, line 521, in do_optTag
Module zope.tal.talinterpreter, line 516, in no_tag
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 861, in do_defineMacro
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 949, in do_defineSlot
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 536, in do_optTag_tal
Module zope.tal.talinterpreter, line 521, in do_optTag
Module zope.tal.talinterpreter, line 516, in no_tag
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 949, in do_defineSlot
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 861, in do_defineMacro
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 861, in do_defineMacro
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 957, in do_defineSlot
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 534, in do_optTag_tal
Module zope.tal.talinterpreter, line 516, in no_tag
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 824, in do_loop_tal
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 536, in do_optTag_tal
Module zope.tal.talinterpreter, line 521, in do_optTag
Module zope.tal.talinterpreter, line 516, in no_tag
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 745, in do_insertStructure_tal
Module Products.PageTemplates.Expressions, line 221, in evaluateStructure
Module zope.tales.tales, line 696, in evaluate
- URL: pageform
- Line 104, Column 10
- Expression: <PathExpr standard:'widget'>
- Names:
{'container': <PloneSite at /plone>,
'context': <PloneSite at /plone>,
'default': <object object at 0xb7dd6528>,
'here': <PloneSite at /plone>,
'loop': {'widget':
<Products.PageTemplates.Expressions.PathIterator object at 0xb248fd8c>},
'nothing': None,
'options': {'args': ()},
'repeat': <Products.PageTemplates.Expressions.SafeMapping object
at 0xb249e32c>,
'request': <HTTPRequest, URL=http://xxxxxxxxxxxxxxxxxxxxx>,
'root': <Application at >,
'template': <ImplicitAcquirerWrapper object at 0xb249e2ac>,
'traverse_subpath': [],
'user': <PropertiedUser 'admin'>,
'view': <Products.Five.metaclass.ImportActivitiesView object at
0xb244898c>,
'views': <zope.app.pagetemplate.viewpagetemplatefile.ViewMapper
object at 0xb249e2cc>}
Module zope.tales.expressions, line 217, in __call__
Module Products.PageTemplates.Expressions, line 161, in _eval
Module Products.PageTemplates.Expressions, line 123, in render
Module zope.app.form.browser.itemswidgets, line 568, in __call__
Module zope.app.pagetemplate.viewpagetemplatefile, line 83, in __call__
Module zope.app.pagetemplate.viewpagetemplatefile, line 51, in __call__
Module zope.pagetemplate.pagetemplate, line 117, in pt_render
Module zope.tal.talinterpreter, line 271, in __call__
Module zope.tal.talinterpreter, line 346, in interpret
Module zope.tal.talinterpreter, line 822, in do_loop_tal
Module zope.tales.tales, line 682, in setRepeat
Module zope.tales.tales, line 696, in evaluate
- URL:
/xxxxxxxxxxxxxxxxx/parts/zope2/lib/python/zope/app/form/browser/orderedSelectionList.pt
- Line 146, Column 8
- Expression: <PathExpr standard:u'view/choices'>
- Names:
{'args': (),
'context': <zope.schema._field.List object at 0xb244816c>,
'default': <object object at 0xb7dd6528>,
'loop': {},
'nothing': None,
'options': {},
'repeat': {},
'request': <HTTPRequest, URL=http://xxxxxxxxxxxxxxxxxxxxxxxxxx>,
'template':
<zope.app.pagetemplate.viewpagetemplatefile.ViewPageTemplateFile object
at 0xb634682c>,
'usage': <zope.pagetemplate.pagetemplate.TemplateUsage object at
0xb24b966c>,
'view':
<zope.app.form.browser.itemswidgets.OrderedMultiSelectWidget object at
0xb249e16c>,
'views': <zope.app.pagetemplate.viewpagetemplatefile.ViewMapper
object at 0xb24b938c>}
Module zope.tales.expressions, line 217, in __call__
Module zope.tales.expressions, line 211, in _eval
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.

Thanks,
JJ
_______________________________________________
Zope-Dev maillist - Zope-Dev[at]zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )


mgedmin at b4net

May 9, 2008, 3:40 AM

Post #2 of 2 (39 views)
Permalink
Re: OrderedMultiSelectWidget in Zope2: context weirdness? [In reply to]

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
Attachments: signature.asc (0.18 KB)

Zope dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.