[Zope] Inserting a variable in a context.manage statement in Python

tim tim@sitefusion.co.uk
Tue, 23 Apr 2002 14:33:41 +0100 (BST)


> c = REQUEST.get('clearing_id','')
> context.manage_addFolder(c) # this works
> # Now what I want to do is add a document to the folder
> # If I include a hard-coded value for the folder name I just created as a
> test, it works
> # But this doesn't:
> context.c.manage_addDocument('NewDoc')

I think you should be able to do either of (both untested):

getattr(context, c).manage_addDocument('NewDoc')
context[c].manage_addDocument('NewDoc')

As far as I understand, your version doesn't work because you are telling
python/zope to look for the c string object that is an attribute of context,
instead of telling it to get hold of the attribute of context that is called
whatever str(c) returns.

hth

tim