[z3-five] using getToolByName in utility

yuppie y.2007- at wcm-solutions.de
Wed Jan 31 13:19:50 CET 2007


Hi Dennis!


Dennis Schulz wrote:
> I made an utility (vocabulary factory) that returns all users. It 
> queries the membership tool. (see code at the end)
> That works fine for displaying it as a dropdown in a formlib form.
> However, when change a value and submit the form, the utility gets 
> called in a weird context by the formlib validation machinery.
> When I print out aq_chain then I only have one object without base request.
> Within this weird context the getToolByName loopup is not possible.

IIRC the validation machinery uses the context bound to the field. 
Something seems to be wrong with the bind() call.

> class UserVocabulary(object):
>     implements(IVocabularyFactory)
>     def __call__(self, context):

What is context and aq_chain(context) here?

>             context = getattr(context, 'context', context)

And what here?

>             context = aq_inner(context)
>             print aq_chain(context)
>             mt = getToolByName(context, 'portal_membership')
>             memberids = mt.listMemberIds()
>             result=[( mt.getMemberById(i).getProperty('fullname'),i) for 
> i in memberids]
>             return SimpleVocabulary.fromItems(result)
> UserVocabularyFactory = UserVocabulary()


HTH,

	Yuppie



More information about the z3-five mailing list