[Zope] Add ZPT at initialization Zope product
Casey Duncan
casey@zope.com
Thu, 30 May 2002 14:04:24 -0400
I'm assuming you are calling=20
parent =3D getattr(self, 'aq_parent', None)
from the __init__ constructor method in the class. One thing to realize i=
s=20
that inside __init__, the object has not been mounted in the ZODB yet and=
=20
therefore has no aq_parent, hence the None result.
Another possibility is that you class does not sublass Acquisition.Implic=
it,=20
which it needs to for aq_parent to work.=20
To get around the former issue check out this ZopeLabs recipe:
http://www.zopelabs.com/cookbook/995468614
hth,
Casey
On Thursday 30 May 2002 11:02 am, Nico de Boer wrote:
> Hi all,
>=20
> I am working on a News product. I have build it in python. It is a
> folderish product and I want that at initialization of the product a
> ZPT is added in the product.
>=20
> I have tried this with DTML Method and it works fine:
>=20
> self.manage_addDTMLMethod('index_html',title=3D'',file=3D'conte=
nts of=20
file')
>=20
> But it isn't working for ZPT. I'm looking for a way to do this, cause
> I need to use the ZPT in my product.
>=20
> I've tried this:
>=20
> parent =3D getattr(self, 'aq_parent', None) =20
> self._createZPT(parent, 'ZPTid', 'title', 'Template')
>=20
> def _createZPT(self, parent, id, title, content):
> """Add a PageTemplate to the News product"""
> parent._setObject(id, ZopePageTemplate.ZopePageTemplate(id,=20
text=3Dcontent))
> getattr(parent, id).pt_setTitle(title)
>=20
> But got the following error from Zope:
>=20
> AttributeError: 'None' object has no attribute '_setObject'
>=20
> The getattr method seems to return None, but the object really has a
> parent.=20
>=20
> Am I forgetting something?
>=20
> Thanks,
>=20
> Greetz Nico
>=20
>=20
>=20
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -=20
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>=20