Re: [Zope-dev] OrderedMultiSelectWidget in Zope2: context weirdness?

2008-05-09 Thread Marius Gedminas
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


signature.asc
Description: Digital signature
___
Zope-Dev maillist  -  Zope-Dev@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 )


[Zope-dev] OrderedMultiSelectWidget in Zope2: context weirdness?

2008-05-08 Thread Josh Johnson (jjmojojjmojo)
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://x,
  '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,