[Zope] Determining object type

Joel Burton joel@joelburton.com
Wed, 6 Mar 2002 12:11:50 -0500 (EST)


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