Determining object type
Hey there, I have a in loop which iterates over two different types of objects. I need to know which type of object I am dealing with in each iteration. This can't be hard , but I cannot find it in the docs. <dtml-in expr="(objectValues('type1')) + (objectValues('type2')"> <dtml-if {I want type 1 here}> processing <dtml-else {type2 by default}> processing </dtml-if> </dtml-in> TIA Sherman
Hi Try the following.... <dtml-in expr="(objectValues(['type1','type2'])"> <dtml-if expr="meta_type=='type1'"> processing <dtml-else {type2 by default}> processing </dtml-if> </dtml-in> hth Laurie -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Sherman Lambert (State Office) Sent: Wednesday, March 06, 2002 10:26 AM To: zope@zope.org Subject: [Zope] Determining object type Hey there, I have a in loop which iterates over two different types of objects. I need to know which type of object I am dealing with in each iteration. This can't be hard , but I cannot find it in the docs. <dtml-in expr="(objectValues('type1')) + (objectValues('type2')"> <dtml-if {I want type 1 here}> processing <dtml-else {type2 by default}> processing </dtml-if> </dtml-in> TIA Sherman _______________________________________________ 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 )
<dtml-in expr="(objectValues('type1')) + (objectValues('type2')"> <dtml-let mt="_.getitem('meta_type')"> <dtml-if "mt=='type 1'"> processing <dtml-else> processing </dtml-if> </dtml-let> </dtml-in> ----- Original Message ----- From: "Sherman Lambert (State Office)" <sherman.lambert@state.co.us> To: <zope@zope.org> Sent: Wednesday, March 06, 2002 4:25 PM Subject: [Zope] Determining object type
Hey there,
I have a in loop which iterates over two different types of objects. I need to know which type of object I am dealing with in each iteration. This can't be hard , but I cannot find it in the docs.
<dtml-in expr="(objectValues('type1')) + (objectValues('type2')"> <dtml-if {I want type 1 here}> processing <dtml-else {type2 by default}> processing </dtml-if> </dtml-in>
TIA Sherman
_______________________________________________ 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 )
On Wed, 6 Mar 2002, Phil Harris wrote:
<dtml-in expr="(objectValues('type1')) + (objectValues('type2')"> <dtml-let mt="_.getitem('meta_type')"> <dtml-if "mt=='type 1'"> processing <dtml-else> processing </dtml-if> </dtml-let> </dtml-in>
Phil -- Why the "_.getitem('meta_type')" followed by separate if statement? I'd have just done this as <dtml-if "meta_type=='xxx'">. Sometimes the _.getitem is required (if you don't know the attribute name, if you want to work w/o acquisition using aq_explicit, etc.). I guess I'm asking: are you being overly cautious/verbose, or is there some risk here in simply doing the </dtml-if meta_type> solution that I'm overlooking? -- Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton Independent Knowledge Management Consultant
meta_type is not always a simple type (i.e. string). if you do if meta_type == 'Folder' for instance it will fail, since meta_type for a folder is a method. using _.getitem returns a string, i.e. it renders it so to speak. but I may always be talking out of my jacksee of course ;) ----- Original Message ----- From: "Joel Burton" <joel@joelburton.com> To: "Phil Harris" <phil@harris-family.info> Cc: <sherman.lambert@state.co.us>; <zope@zope.org> Sent: Wednesday, March 06, 2002 4:51 PM Subject: Re: [Zope] Determining object type
On Wed, 6 Mar 2002, Phil Harris wrote:
<dtml-in expr="(objectValues('type1')) + (objectValues('type2')"> <dtml-let mt="_.getitem('meta_type')"> <dtml-if "mt=='type 1'"> processing <dtml-else> processing </dtml-if> </dtml-let> </dtml-in>
Phil --
Why the "_.getitem('meta_type')" followed by separate if statement?
I'd have just done this as <dtml-if "meta_type=='xxx'">. Sometimes the _.getitem is required (if you don't know the attribute name, if you want to work w/o acquisition using aq_explicit, etc.).
I guess I'm asking: are you being overly cautious/verbose, or is there some risk here in simply doing the </dtml-if meta_type> solution that I'm overlooking?
--
Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton Independent Knowledge Management Consultant
On Wed, 6 Mar 2002, Phil Harris wrote:
meta_type is not always a simple type (i.e. string). if you do if meta_type == 'Folder' for instance it will fail, since meta_type for a folder is a method.
using _.getitem returns a string, i.e. it renders it so to speak.
but I may always be talking out of my jacksee of course ;)
Phil --
Why the "_.getitem('meta_type')" followed by separate if statement?
I'd have just done this as <dtml-if "meta_type=='xxx'">. Sometimes the _.getitem is required (if you don't know the attribute name, if you want to work w/o acquisition using aq_explicit, etc.).
I guess I'm asking: are you being overly cautious/verbose, or is there some risk here in simply doing the </dtml-if meta_type> solution that I'm overlooking?
Interesting. For me (2.5.0), Folder.meta_type is a simple property. In fact, every object seems to have a simple string (grep -r "def meta_type" * in lib/python returned nothing except for PropertySheets.py) However, you're right: why risk it? Product WeirdFoo might emit a dynamic meta_type, strange though that would be. For clarity's sake, thought, wouldn't <dtml-let mt=meta_type> be sufficient over the _.getitem('xxx')? Again, not trying to pick on you, but wondering if I've overly liberal (always a threat) with my dtml-lets. -- Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton Independent Knowledge Management Consultant
Ooo, now I'm starting to take this personally ;) Well, I've only really seen this occur in external Python code (external method/Product). So I may be being a tad anal about the check, but it seems sensible anyway. <dtml-let mt=meta_type> This may very well work, as it may be 'rendering' it in this usage. caveat emptor, again, I may be seeing things through my shite colored glasses ;) ----- Original Message ----- From: "Joel Burton" <joel@joelburton.com> To: "Phil Harris" <phil@harris-family.info> Cc: <sherman.lambert@state.co.us>; <zope@zope.org> Sent: Wednesday, March 06, 2002 5:11 PM Subject: Re: [Zope] Determining object type
On Wed, 6 Mar 2002, Phil Harris wrote:
meta_type is not always a simple type (i.e. string). if you do if meta_type == 'Folder' for instance it will fail, since meta_type for a folder is a method.
using _.getitem returns a string, i.e. it renders it so to speak.
but I may always be talking out of my jacksee of course ;)
Phil --
Why the "_.getitem('meta_type')" followed by separate if statement?
I'd have just done this as <dtml-if "meta_type=='xxx'">. Sometimes the _.getitem is required (if you don't know the attribute name, if you want to work w/o acquisition using aq_explicit, etc.).
I guess I'm asking: are you being overly cautious/verbose, or is there some risk here in simply doing the </dtml-if meta_type> solution that I'm overlooking?
Interesting. For me (2.5.0), Folder.meta_type is a simple property. In fact, every object seems to have a simple string (grep -r "def meta_type" * in lib/python returned nothing except for PropertySheets.py)
However, you're right: why risk it? Product WeirdFoo might emit a dynamic meta_type, strange though that would be.
For clarity's sake, thought, wouldn't <dtml-let mt=meta_type> be sufficient over the _.getitem('xxx')? Again, not trying to pick on you, but wondering if I've overly liberal (always a threat) with my dtml-lets.
--
Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton Independent Knowledge Management Consultant
participants (4)
-
Joel Burton -
Laurie Nason -
Phil Harris -
Sherman Lambert (State Office)