[Zope] reverse sort
Luciano Ramalho
luciano@hiper.com.br
Wed, 12 May 1999 17:11:41 -0300
The following external method has proven VERY useful for us at Hiperlogica.
I believe it does what you want.
____________
WHAT IT DOES
The function returns a list of documents in a folder, sorted by a
'pub_date' string attribute which must be present in all documents. The
sort order is descending. A property of type 'list' named 'exclude' can be
used to list the id's of documents which should not be listed.
_____________________
HOW TO USE IT IN DTML
To generate a list of titles with links:
<!--#in hx_list_docs-->
<A HREF="<!--#var id-->"><!--#var title--></A>
<!--#/in-->
To generate a similar list, but looking inside a folder called 'folder1':
<!--#in expr="hx_list_docs(folder1)"-->
<A HREF="folder1/<!--#var id-->"><!--#var title--></A>
<!--#/in-->
To generate a list with only the tree most recent documents of the current
folder:
<!--#in expr="hx_list_docs(PARENTS[0],3)"-->
<A HREF="<!--#var id-->"><!--#var title--></A>
<!--#/in-->
____
NOTE
We did not use the actual date of the document because (1) we did not know
how to obtain it and (2) our customer wanted to be able to alter the date.
We used 'pub_dates' formatted like this: '1999/05/12 14:32:02'. You could
put anything inside pub_date to determine the sort order.
___________
SOURCE CODE
def hx_list_docs(self, max=0):
dic = {}
#find documents
for doc in self.objectValues(['DTML Document']):
#collect if it is not in the exclude list
if not ( doc.id() in self.exclude ):
dic[doc.pub_date] = doc
dates = dic.keys()
dates.sort()
dates.reverse()
list = []
for date in dates:
list.append( dic[date] )
if (max != 0) and (len(list) == max): break
return list
--
Best regards,
Luciano
--
Hiperlógica <http://hiper.com.br>
Automação de web-sites || Web-site automation