I'm assuming you are calling parent = getattr(self, 'aq_parent', None) from the __init__ constructor method in the class. One thing to realize is that inside __init__, the object has not been mounted in the ZODB yet and therefore has no aq_parent, hence the None result. Another possibility is that you class does not sublass Acquisition.Implicit, which it needs to for aq_parent to work. 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,
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.
I have tried this with DTML Method and it works fine:
self.manage_addDTMLMethod('index_html',title='',file='contents of file')
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.
I've tried this:
parent = getattr(self, 'aq_parent', None) self._createZPT(parent, 'ZPTid', 'title', 'Template')
def _createZPT(self, parent, id, title, content): """Add a PageTemplate to the News product""" parent._setObject(id, ZopePageTemplate.ZopePageTemplate(id, text=content)) getattr(parent, id).pt_setTitle(title)
But got the following error from Zope:
AttributeError: 'None' object has no attribute '_setObject'
The getattr method seems to return None, but the object really has a parent.
Am I forgetting something?
Thanks,
Greetz Nico
_______________________________________________ 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 )