Re: [Zope-dev] Is there a function to get the object type?
On 4/11/06, Takahashi, Michael <[EMAIL PROTECTED]> wrote: > I'm trying to write a function that checks to see if the current object is > a 'Folder'. several ways: isinstance(object, Folder) # does not work in python scripts or object.meta_type == "Folder" # does work in python scripts or object.portal_type == "Folder" # if it's a CMF object. or also: if getattr(object, 'objectIds', None) is not None: This doesn't check if it is a Folder, but if it implements an object manager type interface, which may or may not be what you want. :) Oh, and zope-dev is for development of Zope, not with zope. You should ask in [EMAIL PROTECTED] -- Lennart Regebro, Nuxeo http://www.nuxeo.com/ CPS Content Management http://www.cps-project.org/ ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
RE: [Zope-dev] Is there a function to get the object type?
Thank you to everyone who helped. I've found the answer. In my case, the key was to use 'isPrincipiaFolderish' So to run a check to see if something is a folder: if context.isPrincipiaFolderish: print "It's a folder!" else: print "Nope, it's not a folder." Mike -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Winkler Sent: Monday, April 10, 2006 4:43 PM To: zope-dev@zope.org Subject: Re: [Zope-dev] Is there a function to get the object type? On Mon, Apr 10, 2006 at 03:46:41PM -0700, Takahashi, Michael wrote: > Hi guys, > > I'm trying to write a function that checks to see if the current object > is a 'Folder'. > > I am using this tutorial as a reference: > > http://plone.org/documentation/how-to/pre-populated-folder > > To create a new content object, the following command is used: > > parent.invokeFactory(id=id, type_name='Folder') > > Is there a function that can check what type this newly created object > is? Obviously its 'Folder' in this example, but I'd like to be able to > get the type_name of an object returned anywhere in my site to see if it > is a 'Folder'. This is really a CMF question and belongs on the zope-cmf mailing list; invokeFactory() is a method of CMFCore.PortalFolder. But to answer your question: someobject.portal_type -PW -- Paul Winkler http://www.slinkp.com ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope ) ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Is there a function to get the object type?
On Mon, Apr 10, 2006 at 03:46:41PM -0700, Takahashi, Michael wrote: > Hi guys, > > I'm trying to write a function that checks to see if the current object > is a 'Folder'. > > I am using this tutorial as a reference: > > http://plone.org/documentation/how-to/pre-populated-folder > > To create a new content object, the following command is used: > > parent.invokeFactory(id=id, type_name='Folder') > > Is there a function that can check what type this newly created object > is? Obviously its 'Folder' in this example, but I'd like to be able to > get the type_name of an object returned anywhere in my site to see if it > is a 'Folder'. This is really a CMF question and belongs on the zope-cmf mailing list; invokeFactory() is a method of CMFCore.PortalFolder. But to answer your question: someobject.portal_type -PW -- Paul Winkler http://www.slinkp.com ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
RE: [Zope-dev] Is there a function to get the object type?
Thanks Aruna, That returns all portal_types. However I would like to see what the current type of an object is. For example, if I am currently here: /mysite/index.html I would like to know that the current object is a ‘Document’ And if I were here: /mysite/folder I would like to know that the current object is a ‘Folder’ Thanks, Mike From: Aruna Kathiria [mailto:[EMAIL PROTECTED] Sent: Monday, April 10, 2006 3:58 PM To: Takahashi, Michael; zope-dev@zope.org Subject: RE: [Zope-dev] Is there a function to get the object type? Hello: You can get the types from following function. Once you get the list of the types of the object type, you can use it as you want. ptypes = context.portal_types.objectValues() sample script to test is: --- ptypes = context.portal_types.objectValues() for ptype in ptypes: print ptype return printed -- With Regards, Aruna Kathiriya Sr.Consultant, CIGNEX Technologies, Inc T: 408.327.9900 x 306 F: 408.273.6785 E: [EMAIL PROTECTED] U: www.cignex.com "Implement IT Right" From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Takahashi, Michael Sent: Monday, April 10, 2006 3:47 PM To: zope-dev@zope.org Subject: [Zope-dev] Is there a function to get the object type? Hi guys, I’m trying to write a function that checks to see if the current object is a ‘Folder’. I am using this tutorial as a reference: http://plone.org/documentation/how-to/pre-populated-folder To create a new content object, the following command is used: parent.invokeFactory(id=id, type_name='Folder') Is there a function that can check what type this newly created object is? Obviously its ‘Folder’ in this example, but I’d like to be able to get the type_name of an object returned anywhere in my site to see if it is a ‘Folder’. Thanks, Mike ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
RE: [Zope-dev] Is there a function to get the object type?
Hello: You can get the types from following function. Once you get the list of the types of the object type, you can use it as you want. ptypes = context.portal_types.objectValues() sample script to test is: --- ptypes = context.portal_types.objectValues() for ptype in ptypes: print ptypereturn printed -- With Regards, Aruna Kathiriya Sr.Consultant, CIGNEX Technologies, Inc T: 408.327.9900 x 306 F: 408.273.6785 E: [EMAIL PROTECTED] U: www.cignex.com "Implement IT Right" From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Takahashi, MichaelSent: Monday, April 10, 2006 3:47 PMTo: zope-dev@zope.orgSubject: [Zope-dev] Is there a function to get the object type? Hi guys, I’m trying to write a function that checks to see if the current object is a ‘Folder’. I am using this tutorial as a reference: http://plone.org/documentation/how-to/pre-populated-folder To create a new content object, the following command is used: parent.invokeFactory(id=id, type_name='Folder') Is there a function that can check what type this newly created object is? Obviously its ‘Folder’ in this example, but I’d like to be able to get the type_name of an object returned anywhere in my site to see if it is a ‘Folder’. Thanks, Mike ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )