Re: [Zope] Re: Recursive Python Call in Zope
Can you post your script, so we can see what's wrong with it?
OK, here's my Script: ------------------------ #Args: obj=None, indent=0 (for the view) from Products.PythonScripts.standard import html_quote request = context.REQUEST RESPONSE = request.RESPONSE if obj is None: obj=context folders = obj.objectValues('Folder') if len(folders) > 0: for i in range(len(folders)): folder = folders[i] ind = " " * indent subfolders = folder.objectValues('Folder') print ind + folder.id if len(subfolders) > 0: script(subfolders[i], indent+1) return printed ------------------------ ...it's not very complex - maybe I have to do more Python-practice ;-) thanks for help, C. -- +++ GMX - Mail, Messaging & more http://www.gmx.net +++ NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!
I think I caught my problem... the script()-call was not printed, so I didn't see the return-value... C.
OK, here's my Script:
------------------------ #Args: obj=None, indent=0 (for the view)
from Products.PythonScripts.standard import html_quote request = context.REQUEST RESPONSE = request.RESPONSE
if obj is None: obj=context
folders = obj.objectValues('Folder')
if len(folders) > 0: for i in range(len(folders)): folder = folders[i] ind = " " * indent subfolders = folder.objectValues('Folder') print ind + folder.id if len(subfolders) > 0: script(subfolders[0], indent+1)
return printed ------------------------
...it's not very complex - maybe I have to do more Python-practice ;-)
thanks for help,
C.
-- +++ GMX - Mail, Messaging & more http://www.gmx.net +++ NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!
maybe this is what you want? you also need to print the output of the recursive call ## Script (Python) "test_py" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=obj=None, indent=0 ##title= ## from Products.PythonScripts.standard import html_quote request = context.REQUEST RESPONSE = request.RESPONSE if obj is None: obj=context folders = obj.objectValues('Folder') if len(folders) < 1: return printed for folder in folders: ind = " " * indent print ind + folder.id print script(folder, indent+1) return printed [snip] this would hth, peter. Christopher Baumbach wrote:
Can you post your script, so we can see what's wrong with it?
OK, here's my Script:
------------------------ #Args: obj=None, indent=0 (for the view)
from Products.PythonScripts.standard import html_quote request = context.REQUEST RESPONSE = request.RESPONSE
if obj is None: obj=context
folders = obj.objectValues('Folder')
if len(folders) > 0: for i in range(len(folders)): folder = folders[i] ind = " " * indent subfolders = folder.objectValues('Folder') print ind + folder.id if len(subfolders) > 0: script(subfolders[i], indent+1)
return printed ------------------------
...it's not very complex - maybe I have to do more Python-practice ;-)
thanks for help,
C.
OK... The output is correctly given but now I have the problem, that not all Folders are displayed... The script looks like this: ---------------------------------------------- ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=obj=None, indent=0 ##title= if obj is None: obj=context ind = " " * indent folders = obj.objectValues('Folder') if len(folders) <= 0: return printed for folder in folders: subfolders = folder.objectValues('Folder') if len(subfolders) > 0: print ind + "+" + folder.id print script(subfolders[0], indent+1) else: print ind + "-" + folder.id return printed ---------------------------------------------- I think there's a little silly failure... C.
maybe this is what you want? you also need to print the output of the recursive call
## Script (Python) "test_py" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=obj=None, indent=0 ##title= ##
from Products.PythonScripts.standard import html_quote
request = context.REQUEST RESPONSE = request.RESPONSE
if obj is None: obj=context
folders = obj.objectValues('Folder')
if len(folders) < 1: return printed
for folder in folders: ind = " " * indent print ind + folder.id print script(folder, indent+1)
return printed
[snip]
this would hth, peter.
Christopher Baumbach wrote:
Can you post your script, so we can see what's wrong with it?
OK, here's my Script:
------------------------ #Args: obj=None, indent=0 (for the view)
from Products.PythonScripts.standard import html_quote request = context.REQUEST RESPONSE = request.RESPONSE
if obj is None: obj=context
folders = obj.objectValues('Folder')
if len(folders) > 0: for i in range(len(folders)): folder = folders[i] ind = " " * indent subfolders = folder.objectValues('Folder') print ind + folder.id if len(subfolders) > 0: script(subfolders[i], indent+1)
return printed ------------------------
...it's not very complex - maybe I have to do more Python-practice ;-)
thanks for help,
C.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- +++ GMX - Mail, Messaging & more http://www.gmx.net +++ NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!
On Tue, Nov 19, 2002 at 02:46:59PM +0100, Christopher Baumbach wrote:
OK... The output is correctly given but now I have the problem, that not all Folders are displayed...
you don't loop over the subfolders, you only show the first one:
for folder in folders: subfolders = folder.objectValues('Folder') if len(subfolders) > 0: print ind + "+" + folder.id print script(subfolders[0], indent+1) ^^^^^^^^^^^^^^
-- Paul Winkler http://www.slinkp.com "Welcome to Muppet Labs, where the future is made - today!"
Hi, just another one, which solves your problem... ##parameters=obj=None, indent=0 if obj is None: obj=context print "%s%s" % (' ' * indent , obj.getId()) for folder in obj.objectValues('Folder'): print "%s%s" % (' ' * indent , folder.getId()) for subfolder in folder.objectValues('Folder'): print script(subfolder, indent+1), return printed -mj -- Maik Jablonski __o www.zfl.uni-bielefeld.de _ \<_ Deutsche Zope User Group Bielefeld, Germany (_)/(_) www.dzug.org
participants (4)
-
Christopher Baumbach -
Maik Jablonski -
Paul Winkler -
peter sabaini