[Zope] how to change the metatype??

matt matt@virtualspectator.com
Tue, 23 Oct 2001 09:58:01 +1300


I built the following, with success for simple changes such as these.  All
you have to do is take out the test for the existence of the attribute,
since the object will already have a meta_type.  You then use the
name_value_dict to set the new meta_type.

def upgradeMethod(self,meta_type,name_value_dict,recurse=1):
    """upgrade instances of a product of meta_type to contain new
properties.
    If you need to upgrade something with a dictionary, then you need to
pass the whole dictionary
    in as one of the values.

    Usage : make an external method instance of this method.  Then add a
DTMLMethod that calls this.
    This DTMLMethod is where one decides whether to call this recursively or
just once.  If it is called
    recursivly then every instance will have the same name value pairs
added.  If you need something dynamic
    then you need to call this method non-reursively with the DTMLmethod
controlling the dynamic values and or
    names.  Recursion is set to on by default.

    Example of use :
        <dtml-call "upgradeInstance(this(),'MY_PRODUCT',{'name':value})">
        this will add the attribute name with a value value to any
MY_PRODUCT instance."""


    if self.meta_type == meta_type:
        for i in name_value_dict.keys():
            if not hasattr(self,i):
                setattr(self,i,name_value_dict[i])
        self._p_changed = 1

    if recurse:
        for i in self.getChildNodes():
            upgradeMethod(i,meta_type,name_value_dict)



----- Original Message -----
From: "Robert Rottermann" <robert@redcor.ch>
To: <zope@zope.org>
Sent: Tuesday, October 23, 2001 9:41 AM
Subject: [Zope] how to change the metatype??


> Hi there,
>
> I decided to change the name and the metatype of one of our products.
>
> Since we created a website with it that is about to go online, I would
like
> to be able to change the instances of the product to the new meta type
> programmatically.
>
> How should I do that.
>
> Thanks for your tips.
>
> Robert
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>