Getting properties in Python Methods
Hello, If I have a Python Method in a folder, and the Python Method has a list of strings which are the names of objects in that folder of the type Profile (a ZClass), and I know that each of these objects has a property called profile_name, how do I get the value for that property for each object in the list? Thank you. ---------------------------------------------------------------------- Harry Henry Gebel ICQ# 43675297 West Dover Hundred, Delaware John McCain for President in 2000 http://www.mccain2000.com
One way is to iterate over objectValues(['Profile_meta_class_type']) The meta_type is given during building of the zclass in the product folder. <dtml-in "objectValues(['Meta_type'])"> <dtml-var property </dtml-in> (Above not tested) HTH, __Janko
Sorry, my last mail was unclear. You asked for lookup from a PythonMethod. I have looked into this. The method needs as parameter self. Than this returns the right value. For 'DTML Document' you need to substitute your meta_type # a=self['objectValues'](['DTML Document']) #a=self['objectValues']() b=[] print "A simple test" for i in a: # strange is I can not use hasattr() here??? try: b.append(i.myid) print b except: pass return printed HTHm __Janko
Janko Hauser wrote:
The method needs as parameter self.
Than this returns the right value. For 'DTML Document' you need to substitute your meta_type
# a=self['objectValues'](['DTML Document']) #a=self['objectValues']() b=[] print "A simple test" for i in a: # strange is I can not use hasattr() here??? try: b.append(i.myid) print b except: pass
return printed
Thanks, that did it for sure! Here is my copleted method (tested and working): # List holds html fragments during index construction html = [] # insert all profile object id's and profile_names into list for profile in self['objectValues'](['Profile']): html.append(profile.id + '">' + profile.profile_name) # join fragments together html = '<a href="' + string.join(html, '</a><br>\n<a href="') + '</a><br>\n' return html Your advise also showed me how to filter for a particular meta_type; before I was just getting a list of object ids and using if/else to make the object id was not in a hard coded list of the objects in the folder that were not 'Profile's . Needless to say my method hampered expandability and portability; yours was a big improvement. Thanks alot! ---------------------------------------------------------------------- Harry Henry Gebel ICQ# 43675297 West Dover Hundred, Delaware John McCain for President in 2000 http://www.mccain2000.com
participants (2)
-
Harry Henry Gebel -
Janko Hauser