[Zope-CMF] R: Portal type = None

Tres Seaver tseaver@zope.com
25 Nov 2002 12:06:15 -0500


On Mon, 2002-11-25 at 10:32, Vladimir Iliev wrote:

> On Mon, 2002-11-25 at 17:17, trashMan wrote:
> > Help, please!!
> >=20
> > I have the same problem!
> > where  must i do "portal_type =3D meta_type =3D 'Type'" ??=20
> >=20
> > Max
> >=20
> > -----Messaggio originale-----
> > Da: zope-cmf-admin@zope.org [mailto:zope-cmf-admin@zope.org] Per conto
> > di Chris McDonough
> > Inviato: venerd=EC 9 agosto 2002 22.06
> > A: 220hex; zope-cmf@zope.org
> > Oggetto: Re: [Zope-CMF] Portal type =3D None
> >=20
> >=20
> > Evidently CMF 1.2 used to automatically set an object's portal_type to
> > its meta_type if it didn't exist.  This no longer happens in 1.3. So yo=
u
> > need to explicitly declare a portal_type on these objects. The simplest
> > way to do this is "portal_type =3D meta_type =3D 'Type'"

Nope.  The portal_types tool still sets that value inside
'constructInstance';  the likeliest way to get an instance without its
portal_type set is to construct is some other way (e.g., via the ZMI).

> >=20
> > ----- Original Message -----
> > From: "220hex" <gif@220hex.org>
> > To: <zope-cmf@zope.org>
> > Sent: Friday, August 09, 2002 3:12 PM
> > Subject: [Zope-CMF] Portal type =3D None
> >=20
> >=20
> > > For some strage reason during the upgrade from CMF 1.2 to 1.3,
> > most of my
> > > portal documents have lost their type definition. When I go to the
> > workflow
> > > tag for these documents it says:
> > > ------
> > > This object's portal type is: None.
> > >
> > > This object doesn't belong to any workflow.
> > > ------
> > > Even stranger is the fact that I run two different CMF instances,
> > but only
> > > the oldest one is affected.
> > >
> > > Is there any way I can programatically change the portal type on
> > these
> > > documents?
> > > I hate the idea of having to manually recreate hundreds of docs :(

To repair this, write an ExternalMethod which runs through all the
instances in your site, and uses other clues (e.g., the meta_type, or
whatever) wo reconstruct the portal_type.  E.g.:

  for brain in self.portal_catalog.searchResults( portal_type=3DNone ):
      object =3D brain.getObject()
      if object.meta_type =3D=3D 'Document':
         object.portal_type =3D 'Document'
      #....

Then recatalog everything by pushing the "Update" button on the workflow
tool.

> class blablabla(Document):
>=20
>   meta_type =3D portal_type =3D 'blablabla'

Please note that 'portal_type' is supposed to be an instance attribute,
not a class attribute, and that it is set by the types tool when content
objects are created through it, as they should be.  *Never* create CMF
content objects via the ZMI:  that way lies madness.

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