object properties
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
Hi, I have the following in a dtmlDocument. <dtml-tree branches_expr="folder_of_things.objectValues(['Folder', 'DTML Document'])"> <dtml-var id> </dtml-tree> the folder folder_of_things contains numerous things, including some documents and folders. The problem seems to be that each time I expand the tree node, I get a repeat of the original list of nodes, as if it is listing itself recursively, but not decending down the object hierachy. An when I roll over a node '+' of one of the documents is : http://localhost:8080/admin_test/some_tree_examples?tree-e=eJyLVneEAteqbFt1H... if I expand the tree and roll over the repeat entry I get the same link. What's happening? I am running 2.2.2 stable. By they way : the simple example in the user man doesn't return anyhthing on a folder that itself contains folders and dtml documents. I.e. <dtml-tree> <dtml-var id> </dtml-tree> any help would be greatly appretiated, Matt Bion
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
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
Matt wrote:
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()">.
i made a simple error. this code is tested and works properly (i had set PropList to a string instead of a list) <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-var PropList> This will show all the properties of an object (zclass, folders, documents, etc).
If I used <dtml-let sheet=sequence-key> instead, then I always got back only two strings, "default" and "webdav".
these are the names of the propertysheets of the folder.
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.
you mentioned above that you tried this in a folder with a couple of other folders and images in it, if what you're trying to do is iterate over them than you're not looking for object properties but subobjects (attrs) which can be iterated through using <dtml-in "objectIds(['Folder'])"> <dtml-var sequence-item> <dtml-in> also check out objectItems, objectValues. or using the ZDOM methods. regardless the http://www.zope.org/Members/ZQR is always your friend. Cheers Kapil
I tried a few things and found the following useful : Property ids of <dtml-var "PARENTS[0].id"> are <dtml-var "PARENTS[0].propertyIds()"> 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
Matt wrote:
I tried a few things and found the following useful :
Property ids of <dtml-var "PARENTS[0].id"> are <dtml-var "PARENTS[0].propertyIds()">
And of you want to actually see property values, you could try <dtml-var propertyItems> which generates id/property tuples. Craig -- Craig Allen - Managing Partner - Mutual Alchemy Web Architecture - http://alchemy.nu
participants (3)
-
Craig Allen -
Kapil Thangavelu -
Matt