[Zope] More ZClass questions: How to get a complete property list?
Ernesto Revilla
aerd@retemail.es
Tue, 30 Jan 2001 00:57:16 +0100
Hi there,
I want to have a method which returns a list of all properties of an object.
The problem: when I write a Method (DTML or Python) I always get the
properties of the container of the method, but not the ones of the object I
applied the method. I used propertyMap, propertyIds and propertyItems.
Example:
Say xxx is an instance of a ZClass and resides in the root directory.
http://localhost:8080/xxx/propertyMap
will return a map of all properties of the root folder not of the xxx
object.
Say you define a method yyy which access concrete properties of the object
with dtml-var, say ''who" and "when", then it will access these properties
if they exist and fail if one of these doesn't.
Ok. I found it, I have to access each propertysheet, but if I try something
like
<dtml-in "propertysheets">
<dtml-var propertyMap>
</dtml-in>
the login window with username/password is presented, but whatever I type I
get an authorization error, so I think there is a private properysheet,
isn't it?
So how can I get a list of all properties defined in an object?
I'll answer the question myself, but I think it is a bit complex. The
philosophy is to write nearly everything in Python????
External (unrestricted) Pyhton script (like id=getprops, module=getprops,
function=getprops) :
def getprops(self):
x=[]
for y in self.propertysheets:
for z in y.propertyItems():
x.append(z)
return x
Now a DTML method for displaying this (e.g. as printproperties):
<dtml-var standard_html_header>
<h2>Properties of <dtml-var title_or_id></h2>
<p>
<ul>
<dtml-in getprops>
<li><dtml-var sequence-key>: <dtml-var sequence-item>
</dtml-in>
</ul>
regards,
Erny