I want to add an index_html to my folderiod object, but I only want to do that if the parent object is not the same as the object that I am adding. I thought I could use the isinstance() function but I get this message. Sorry, an error occurred.<p> <!-- Traceback (innermost last): File /home/sroberts/src/Zope-1.9b1-src/lib/python/ZPublisher/Publish.py, line 861, in publish_module File /home/sroberts/src/Zope-1.9b1-src/lib/python/ZPublisher/Publish.py, line 583, in publish (Info: /manage_addZlilBlackBook) File /home/sroberts/src/Zope-1.9b1-src/lib/python/Products/ZlilBlackBook/ZlilBlackBook.py, line 22, in addZlilBlackBook (Object: ApplicationDefaultPermissions) TypeError: second argument must be a class --This is the function where the error occurs------------- def addZlilBlackBook(self, id, title='', organization='', phone='', REQUEST=None): """Method to add a Address book to Zope""" NewBook = ZlilBlackBook(id, title, organization, phone) if isinstance(self, ZlilBlackBook): NewBook.test = "Parent is a BlackBook" else: NewBook.test = "Parent is not a BlackBook" # Self is the folder that will contain our new object self._setObject(id, NewBook ) # return to the parent object's manage_main if REQUEST is not None: return self.manage_main(self,REQUEST) ---------------------------------------- This class is defined in the same file as this function. Is there some weird scoping issue that I am not aware of? --------------------------------------------------- - Scott Robertson Phone: 714.972.2299 - - CodeIt Computing Fax: 714.972.2399 - - http://codeit.com - ---------------------------------------------------
At 09:27 AM 12/11/98 -0800, Scott wrote:
This class is defined in the same file as this function. Is there some weird scoping issue that I am not aware of?
I would guess that the problem is that most of Zope's classes are actually ExtensionClasses. Python 1.5.1 (#0, Apr 13 1998, 20:22:04) [MSC 32 bit (Intel)] on win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
import Acquisition class A(Acquisition.Implicit):pass ... type(A) <extension class ExtensionClass at 00BEC778> a=A() isinstance(a,A) Traceback (innermost last): File "<stdin>", line 1, in ? TypeError: second argument must be a class
Probably the easiest solution is to add a class attribute like: class MyProduct(... isMyProduct=1 ... Then you can do things like: if hasattrib(self.aq_parent,'isMyProduct') and self.aq_parent.isMyProduct: print 'I am within another MyProduct object' Maybe there are better solutions... -Amos
participants (2)
-
Amos Latteier -
Scott Robertson