[Zope] object properties

Kapil Thangavelu kthangavelu@earthlink.net
Sat, 14 Oct 2000 05:47:29 -0700


Matt wrote:
> 
> Can someone give me an example, either in dtml or external methods of
> accessing or listing the properties of the current object I am calling a
> method on.
> 
> Or point me to a source
> 
> Matt Bion


you can ask an object what properties it has and retrieve them through
dtml, like

<dtml-if "_.hasattr(this(), 'foobar')">
	<dtml-var foobar>
	or if you want a reference, instead of a string
	<dtml-var "_.getattr(this(), 'foobar')">
</dtml-if>

if you want to examine the propertys of an object you can go iterate
through its propertysheets (works for a zclass, the rest i'm not sure). 
You can reference the Zope Quick Reference for more info.

<dtml-call "REQUEST.set('PropList', '')">

<dtml-in "propertysheets.items()">
<dtml-let sheet=sequence-item>
<dtml-in "sheet.propertyItems()">

<dtml-let prop=sequence-key>
<dtml-call "REQUEST['PropList'].append(prop)">
</dtml-let>

</dtml-in>
</dtml-let>
</dtml-in>


<dtml-if "'foobar' in PropList or
	 'barfoo' in PropList or
	 'guesswho' in PropList">

	Success

</dtml-if>



Kapil