[Zope] Creating products

Paul Winkler pw_lists at slinkp.com
Sun Aug 17 17:34:40 EDT 2003


On Sun, Aug 17, 2003 at 01:29:05PM -0500, Dustin Mitchell wrote:
> I'm still not clear where the attributes for
> 
>   context.manage_addProduct['Volunteer']
> 
> come from -- if I added .foo() to the end of that, where would Zope
> look for 'foo'?

It's a bit convoluted, but if you explore in lib/python/App, you find out:

context.manage_addProduct['Foo'] looks up 'Foo' by traversing
the ProductDispatcher; 
which in turn calls ProductRegistry._getProducts();
which tries to find 'Foo' in Control_Panel.Products, which is
an instance of ProductFolder; 
your Product should be in that Product Folder.

Now, looking again at your problem, to which I should have paid closer 
attention:

> Inside the manage_addVolunteerSite :

whoops, there's your problem, see below.

> ... 
>
>  volunteersite.manage_addProduct['Volunteer'].manage_addVolunteerUserFolder()
>
> ...
> 
> causes:
>
> Error Type: AttributeError 
> Error Value: _getProducts

>From this we can see that when you make this call, something 
is wrong with volunteersite such that it can't find _getProducts. 

The problem is that you are doing this before volunteersite itself
is ready for use within the zope app. The object exists, but IIRC it's 
not really placed in in its container yet and has no access to other 
zope objects, until after manage_addVolunteerSite() has returned and 
the containing ObjectManager has finished doing whatever it does 
when you add stuff.  (I forget, but a look at the ObjectManager 
could would tell you what happens.) So this is why the attempt to 
acquire _getProducts fails.

Solution: Move the volunteersite.manage_addProduct... call out of 
manage_addVolunteerSite, and instead put it in VolunteerSite.manage_afterAdd.
This is where you should put any add-time stuff that depends on having a fully
working zope context.

-- 

Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's THE DEMON!
(random hero from isometric.spaceninja.com)



More information about the Zope mailing list