[Zope] Getting properties in Python Methods

Harry Henry Gebel zope@zope.org" <zope@zope.org
Sat, 04 Dec 1999 03:54:44 +0000


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