[Zope-CMF] getting an object's factory

Tres Seaver tseaver@zope.com
26 Feb 2003 08:53:05 -0500


On Wed, 2003-02-26 at 07:58, Mark McEahern wrote:
> Suppose I have a portal object and I want to serialize (to disk) the minimum
> amount of information I need to create another one.  I'm currently doing
> this:
> 
>   # Store type_name on disk.
>   type_name = item.getTypeInfo().Title()

Rather than using the (possibly L10N-ized) Title() method of the type
info object, just use the 'getPortalTypeName()' method of the item:

    # Store type_name on disk.
    type_name = item.getPortalTypeName()

>   # later, I can create an instance...
>   parent.invokeFactory(type_name=type_name, id=new_id)
> 
> Is the fact that this currently works coincidental?

Nope.  the type_name bit is first and foremost an ID for the
"constructor" or "factory" for objects of that type;  your usage is
perfectly canonical.

>  Is there a clearer
> approach?  I'm purposefully not spelling out more of the approach because I
> assume it's irrelevant.  I'm probably wrong about that.  ;-)

Serializing content to the filesystem in a general way is a tricky
problem.  If you have only a bounded set of content types to deal with,
you can usually do a pretty good job (e.g., using the 'manage_FTPGet'
representation should work pretty well for most of the CMFDefault's
content types).

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com