Personal tools
You are here: Home Lists ZPUG DC List Archives 2005 2005-08 right way to add portal type programmatically? / Christoph Berendes <berendes@netalyst.com>
Navigation
Log in


Forgot your password?
New user?
Mailing Lists
You can read our ZPUGDC mailing list archives online.
You can subscribe to our mailing list:
Book Review

The Definitive Guide to Plone

Reviewer: joel
 

right way to add portal type programmatically? / Christoph Berendes <berendes@netalyst.com>

right way to add portal type programmatically?
Christoph Berendes <berendes(at)netalyst.com>
2005-08-11 12:58:19 [ FULL ]
We've developed a product that, for various reasons, needs to install an 
Image portal type upon install.
The code below, run as part of the Customization policy for a new 
Product-based site, works fine the first time I run it in a Zope instance.

When I run it a second time (in same Zope instance, but a different 
Plone site), it dies with the error shown below. Oddly, if I restart the 
Zope instance, I can run this code again once. So a "restart" somehow 
resets this problem.

What's the right way to add a custom portal type?

Code: (self is the Plone site being created)
[...]

Error on second attempt after Zope restart:
[...]

Re: [ZPUGDC] right way to add portal type programmatically? / Matthew T.Kromer <MATTHEW.T.KROMER@saic.com>

Re: [ZPUGDC] right way to add portal type programmatically?
Matthew T.Kromer <MATTHEW.T.KROMER(at)saic.com>
2005-08-11 13:07:38 [ FULL ]
Uh, the reason it's puking is because you're trying to manually slam 
the factory type information into place without registering the type 
object using the more normal type registration process.

You want to register the factory type information in your __init__ 
scripts (see any Plone or CMF product, they'll all adjust FTI 
information).

Then you want to actually add the type to the types tool, ie, you want 
to invoke the factory based type information type install to the types 
tool.

If you peek at it, the ZMI invokes the manage_addTypeInformation method 
on the types_tool object; thats what you want to do too, e.g. in your 
code, invoke pt.manage_addTypeInformation(id='',typeinfo_name='PRODUCT: 
Type Name')

Usually you run that kind of install code in your Extensions/install.py 
file's install method.


On Aug 11, 2005, at 2:01 PM, Christoph Berendes wrote:
[...][...][...][...][...]

Re: [ZPUGDC] right way to add portal type programmatically? / Christoph Berendes <berendes@netalyst.com>

Re: [ZPUGDC] right way to add portal type programmatically?
Christoph Berendes <berendes(at)netalyst.com>
2005-08-11 13:49:39 [ FULL ]
On 8/11/05 2:09 PM, Matthew T.Kromer wrote:
[...]


Thanks.

Checking
    if id not in typesTool.objectIds():

seems to have done the trick. I infer that adding the custom type the 
first time both adds it to Plone site #1, and to the portal_types tool, 
which then automagically adds it to the second site. Interesting.

Re: [ZPUGDC] right way to add portal type programmatically? / Matthew T.Kromer <MATTHEW.T.KROMER@saic.com>

Re: [ZPUGDC] right way to add portal type programmatically?
Matthew T.Kromer <MATTHEW.T.KROMER(at)saic.com>
2005-08-11 14:04:14 [ FULL ]
Well, keep in mind there's the Product information, and then there's  
types tool information.  Product information is global to Zope; its  
handled at the module level and isn't persistent.  Types tool  
information is local to a Plone site, and *is* persistent.  Product  
registration happens only once, at Zope startup.  types_tool type  
registration can happen any time.


On Aug 11, 2005, at 2:53 PM, Christoph Berendes wrote:
[...][...][...]

Powered by Plone, the Open Source Content Management System

This site conforms to the following standards: