ZPT reverse ordering
I want to list items on a page with the newest at the top. I have got part of the way there with this code: <tr tal:define="thelist python:p.objectValues('Kube')" tal:repeat="subitems python:sequence.sort(thelist, (('bobobase_modification_time',),) )"> Two problems with this though: 1) I want it sorted by the creation date, rather than modification date. 2) I need the results reversed so newest is at the top, not bottom. I suspect I need to create a python script to build the list. Does anyone have the code to do this? Cheers Tom
Hello Tom, Thursday, May 2, 2002, 8:06:53 PM, you wrote: TN> 2) I need the results reversed so newest is at the top, not bottom. i think this will help getting it reversed tal:repeat="subitems python:sequence.sort(thelist,(('bobobase_modification_time','desc'),))"> :-) -- Geir Bækholt web-developer geirh@funcom.com funcom oslo | webdev-team
TN> 2) I need the results reversed so newest is at the top, not bottom.
i think this will help getting it reversed
tal:repeat="subitems
python:sequence.sort(thelist,(('bobobase_modification_time','d esc'),))">
Thanks for your help. I get an error when I try this though: Error Type: TALESError Error Value: exceptions.AttributeError on 'None' object has no attribute 'getitem' in "", at line 160, column 3 If I take out the 'desc' then it works fine. Any ideas? Hang on a minute, I just fixed it! I replaced bobobase_modification_time with bobobase_creation_time, and left out the 'desc'. It now shows the most recent first. T.
on or about, Friday, May 03, 2002, we have reason to believe that Tom Nixon wrote something along the lines of :
i think this will help getting it reversed tal:repeat="subitems python:sequence.sort(thelist,(('bobobase_modification_time','d esc'),))">
TN> Thanks for your help. I get an error when I try this though: TN> Error Type: TALESError TN> Error Value: exceptions.AttributeError on 'None' object has no attribute TN> 'getitem' in "", at line 160, column 3 sorry .. my fault , you need a comparisations function in there too. still untested: sort(thelist,(('bobobase_modification_time','cmp','desc'),)) TN> If I take out the 'desc' then it works fine. Any ideas? TN> Hang on a minute, I just fixed it! I replaced bobobase_modification_time TN> with bobobase_creation_time, and left out the 'desc'. It now shows the TN> most recent first. well . the "desc" setting could come in handy anyway.. :-) :-) -- Geir Bækholt web-developer geirh@funcom.com funcom oslo | webdev-team
On Fri, May 03, 2002 at 10:39:29AM +0100, Tom Nixon wrote: | > python:sequence.sort(thelist,(('bobobase_modification_time','d | > esc'),))"> | | Thanks for your help. I get an error when I try this though: | | Error Type: TALESError | Error Value: exceptions.AttributeError on 'None' object has no attribute | 'getitem' in "", at line 160, column 3
l = [ 3 , 2 ] print l [3, 2] print l.sort() None print l [2, 3]
The sort() method modifies the list in-place and returns None. You are trying to iterate over the return value of sort(), which doesn't have a getitem method. The simplest solution is to sort the list after you have a reference to it. Eg: tal:define="l python:[3,2] ; foo l.sort()" As a side effect it creates 'foo' as a reference to None, but that isn't significant. -D -- An anxious heart weighs a man down, but a kind word cheers him up. Proverbs 12:25 GnuPG key : http://dman.ddts.net/~dman/public_key.gpg
I replaced bobobase_modification_time with bobobase_creation_time, and left out the 'desc'. It now shows the most recent first.
I was talking nonsense! The correct result was a fluke. There's no such thing as bobobase_creation_time. I see it's in the collector. I hope it gets implemented soon, I can't imagine it's too big a job. http://collector.zope.org/Zope/188 T.
participants (4)
-
dman -
Geir Bækholt -
Geir B�kholt -
Tom Nixon