[Zope] Python and getting first object

Tuttle, Gene cetuttle at rottlundhomes.com
Mon Sep 13 16:28:38 EDT 2004


here is the python code that I came up with.
Is there a better way?

from Products.PythonScripts.standard import html_quote

import string


name=""
newpath=""
path="/SAS/PDFforms/rottlund/mn/"

while len(name) == 0:
	test_obj = context.restrictedTraverse(path)
	for object in test_obj.objectValues():
		if object.getProperty('generic_name') == 'lothold':
			name = object.getId()
#  if name is 0 lop off the end folder and search again
	if len(name) == 0:
		# remove the trailing / if it is there
		if path[-1] == '/':
			path = path[:-1]
		path_parts = string.split(path, '/')
		folder_elements =  len(path_parts) -1
		# clear out the last element
		path_parts[folder_elements] = ""
		newpath = string.join(path_parts,'/')
		path = newpath

print path  +  name
		

return printed





-----Original Message-----
From: Tuttle, Gene [mailto:cetuttle at rottlundhomes.com]
Sent: Monday, September 13, 2004 12:31 PM
To: Zope Mail List (E-mail)
Subject: [Zope] Python and getting first object


I am new to Zope.
I have a folder tree of PDF documents.
The documents are location and division specific. 
IE:  a lot hold pdf will contain the same field data but will display
different logos or text depending on the location.
A form may also be generic. 

given this folder structure

PDFforms
	DavidBernard
 	Rottlund
                    MN
                    WI
                    IA
                    FL

In these folders are PDF documents.
Each document will have a property of 'generic_name' and 'active'
I want to use python to search starting at the lowest level in the tree to
find the first document that 
matches the generic_name and active properties

I used this code snipit.

for object in context.SAS.PDFforms.rottlund.mn.objectValues():
	if object.getProperty('generic_name') == 'lothold':
		print object.title
return printed

but this did not find the form in the Rottlund folder that matched the
request.
If i use:
for object in context.SAS.PDFforms.rottlund.objectValues():
	if object.getProperty('generic_name') == 'lothold':
		print object.title
it finds the document ( note the path changed - the mn)

Can someone point me in the right direction.

Thanks 
Gene
_______________________________________________
Zope maillist  -  Zope at zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


More information about the Zope mailing list