On Mon, Jan 01, 2007 at 11:47:28PM +0000, Michael Foord wrote:
> So your patch just allows the passing in of a comparison function to th=
e=20
> sidebar function.
> If a comparison function is passed in, it is used to sort the pages.
Yes, simple, but useful.
> It sounds fine. Can you give me an example function I can put in the do=
cs ?
Well, how about this (adapted from the sidebar example): sorting by crumb
value, inverse order.
.. raw:: html
=20
{+coloring}
=20
cmp_page =3D lambda page1, page2 : 2*(page1['crumb'] < page2['crumb'] ) =
- 1
for page in sidebar(indextree, cmp=3Dcmp_page):
val =3D page['crumb']
link =3D page['target']
if page['title']:
print '<br /><strong><a href=3D"%s">%s</a></strong>' \
% (link, val)=20
else:
print '<br /><a href=3D"%s">%s</a>' % (link, val)
=20
{-coloring}
But this allows for much more powerful uses (like having a "date"
uservalue, and sorting by date).
Cheers,
Ga=EBl
|