[Zope] object properties
Matt
matt.bion@eudoramail.com
Sun, 15 Oct 2000 09:43:40 +1300
Thanks for your response. I tried your methods on a normal folder that
contains some other folders, dtmldocuments, and images, but it failed on the
<dtml-let sheet=sequence-item> which followed the <dtml-in
"propertysheets.items()">.
If I used <dtml-let sheet=sequence-key> instead, then I always got back only
two strings, "default" and "webdav". So I guess it is picking something else
up. Any ideas? Perhaps I should be using ZClasses, but I just wanted to
have what I thought would be the simple ability to loop through properties of
an object without knowing what they were before.
thanks
Matt Bion
Kapil Thangavelu wrote:
> 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