I can't seem to find the straight dope on this one in the documentation. I have a Python product, named Volunteer. It has several classes defined within it (VolunteerUserFolder, Opportunity, etc.). Each class defines constructors e.g., manage_addOpportunity and manage_addOpportunityForm. In order to instantiate one of these classes programmatically, I know I need to do something like: context.manage_addProduct['Volunteer'].manage_addOpportunity(title="hi") but this doesn't seem to work -- manage_addOpportunity is not found. I know that context.manage_addProduct['Volunteer'] is some sort of proxy for my product, but what is the list of attributes I can access from this point (not counting acquisition, obviously)? If I wanted to add a static product-level function (for example, run_background_check(ssn)), where would I put that function? Thanks to anyone who can shed some light on all of this or direct me toward a snippet of documentation I haven't found :-) Dustin -- Dustin Mitchell dustin@ywlcs.org/djmitche@alumni.uchicago.edu http://people.cs.uchicago.edu/~dustin/ PGP Key: http://people.cs.uchicago.edu/~dustin/pubkey.txt
On Sun, 2003-08-17 at 06:45, Dustin Mitchell wrote:
I can't seem to find the straight dope on this one in the documentation.
Yeah... once you get the recipe right, it's smooth sailing though. Your problem probably stems from one (or more) of the following: 1. The product isn't installed correctly 2. Your classes aren't registered correctly 3. Your product isn't compiling First off, is the product should consist of a folder with a main module and an initialization module called __init__ (if you don't have one of these, look at the Boring product for a good template). If you haven't done so already, add an empty file to your product folder called refresh.txt. This will add a "refresh" tab to your product management screens and will greatly facilitate debugging. You will need to restart Zope for it to "see" a newly-added product. Having done that, are you able to see the product in the Products folder of the Control Panel in the ZMI? Does it have a "broken" icon? What do you see if you open the product's management screens? Look at its refresh screen? Check that out, take note of any tracebacks and let us know what you see. HTH Dylan
On Sun, Aug 17, 2003 at 10:54:14AM -0700, Dylan Reinhardt wrote:
On Sun, 2003-08-17 at 06:45, Dustin Mitchell wrote:
I can't seem to find the straight dope on this one in the documentation.
Yeah... once you get the recipe right, it's smooth sailing though.
Your problem probably stems from one (or more) of the following: 1. The product isn't installed correctly 2. Your classes aren't registered correctly 3. Your product isn't compiling
First off, is the product should consist of a folder with a main module and an initialization module called __init__ (if you don't have one of these, look at the Boring product for a good template).
If you haven't done so already, add an empty file to your product folder called refresh.txt. This will add a "refresh" tab to your product management screens and will greatly facilitate debugging.
You will need to restart Zope for it to "see" a newly-added product.
Having done that, are you able to see the product in the Products folder of the Control Panel in the ZMI? Does it have a "broken" icon? What do you see if you open the product's management screens? Look at its refresh screen?
Check that out, take note of any tracebacks and let us know what you see.
Nope, product (which is already quite well along) is installed correctly, adding from the ZMI works just fine, etc. Inside the manage_addVolunteerSite : ... volunteersite.manage_addProduct['Volunteer'].manage_addVolunteerUserFolder() ... causes: Error Type: AttributeError Error Value: _getProducts the text is: Traceback (innermost last): Module ZPublisher.Publish, line 98, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module Products.Volunteer.VolunteerSite, line 65, in manage_addVolunteerSite Module App.FactoryDispatcher, line 26, in __getitem__ Module App.FactoryDispatcher, line 29, in __bobo_traverse__ AttributeError: _getProducts However, this works: acl_users = VolunteerUserFolder() volunteersite._setObject('acl_users', acl_users); but clearly isn't the best way to do things; besides, there will be other circumstances when I will want to add products from Python Script objects. So what am I doing wrong? Dustin -- Dustin Mitchell dustin@ywlcs.org/djmitche@alumni.uchicago.edu http://people.cs.uchicago.edu/~dustin/ PGP Key: http://people.cs.uchicago.edu/~dustin/pubkey.txt
On Sun, Aug 17, 2003 at 01:03:40PM -0500, Dustin Mitchell wrote:
Nope, product (which is already quite well along) is installed correctly, adding from the ZMI works just fine, etc.
Inside the manage_addVolunteerSite :
... volunteersite.manage_addProduct['Volunteer'].manage_addVolunteerUserFolder() ...
causes:
Error Type: AttributeError Error Value: _getProducts (snip)
However, this works:
acl_users = VolunteerUserFolder() volunteersite._setObject('acl_users', acl_users);
I would guess that the problem is Dylan's second possible diagnosis:
2. Your classes aren't registered correctly
In your __init__.py should be an initialize() function that calls context.registerClass for *each* class class that you want to be an addable Product. Have you done this? E.g. from Max M's Minimal Product howto: import minimal def initialize(context): """Initialize the minimal product. This makes the object apear in the product list""" context.registerClass( minimal.minimal, constructors = ( minimal.manage_addMinimal, # This is called when # someone adds the product ) ) -- Paul Winkler http://www.slinkp.com Look! Up in the sky! It's MARMITE INDEFATIGABLE SALESMAN MAN! (random hero from isometric.spaceninja.com)
On Sun, Aug 17, 2003 at 02:15:41PM -0400, Paul Winkler wrote:
On Sun, Aug 17, 2003 at 01:03:40PM -0500, Dustin Mitchell wrote:
Nope, product (which is already quite well along) is installed correctly, adding from the ZMI works just fine, etc.
Inside the manage_addVolunteerSite :
... volunteersite.manage_addProduct['Volunteer'].manage_addVolunteerUserFolder() ...
causes:
Error Type: AttributeError Error Value: _getProducts (snip)
However, this works:
acl_users = VolunteerUserFolder() volunteersite._setObject('acl_users', acl_users);
I would guess that the problem is Dylan's second possible diagnosis:
2. Your classes aren't registered correctly
In your __init__.py should be an initialize() function that calls context.registerClass for *each* class class that you want to be an addable Product. Have you done this? E.g. from Max M's
Of course: def initialize(registrar): ... registrar.registerClass( VolunteerUserFolder, permission = 'Add Volunteer Objects', icon = "icons/vuf.png", constructors = (manage_addVolunteerUserFolder,), ) (same effect with classes which have two constructors---(manage_addX, manage_addXForm) ) 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'? Thanks for the thoughts so far.. Dustin -- Dustin Mitchell dustin@ywlcs.org/djmitche@alumni.uchicago.edu http://people.cs.uchicago.edu/~dustin/ PGP Key: http://people.cs.uchicago.edu/~dustin/pubkey.txt
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)
participants (3)
-
Dustin Mitchell -
Dylan Reinhardt -
Paul Winkler