[Zope] Output child folders in a specifc order?
Tim Hicks
tim@sitefusion.co.uk
Tue, 1 Oct 2002 18:17:58 +0100
----- Original Message -----
From: <JBeard@porternovelli.com>
To: <zope@zope.org>
Sent: Tuesday, October 01, 2002 5:48 PM
Subject: [Zope] Output child folders in a specifc order?
[...]
> It looks in my content folder and outputs links to all folders in there.
> The links come through as some random order, I want to be able to control
> this order, not alpha, but a defined order:
> I have 5 folders, I want to be able to tell it which ones to output 1st,
> 2nd, etc >> This will then form my navigation.
Hmm, very topical for me. I needed this just last week and came up with the
following script. No guarantees on efficiency, but it does what I want.
Improvements gratefully accepted
#########
obs = []
order_prefs = {'indoor':1, 'outdoor':2, 'pool':3, 'hlsm':4, 'classes':5,
'corporate':6, 'department':7}
def order_sort(ob1, ob2):
try:
return cmp(order_prefs[ob1.getId()], order_prefs[ob2.getId()])
except KeyError:
return 0
home = context.sport_root() # This is a custom script of mine that returns
the root of my site
for folder in home.objectValues(['Folder',]):
if folder.hasProperty('inTopMenu'):
obs.append(folder)
obs.sort(order_sort)
#put the sport site root object first
obs.insert(0, home)
return obs
#########
cheers,
tim