I have a script that uses getId to get all structured text documents in a folder. Each of those documents has an added property called 'priority' which is a string type. The value of 'priority' is is used to impose a sort order on the documents. However, I can't figure out how to sort the objects using the the sort method of lists. Any recommendations?
I'd make a list of two element tuples (first element being the priority, second being the document object), sort it, then if required make it a list of just the document objects. David Bear wrote:
I have a script that uses getId to get all structured text documents in a folder. Each of those documents has an added property called 'priority' which is a string type. The value of 'priority' is is used to impose a sort order on the documents. However, I can't figure out how to sort the objects using the the sort method of lists. Any recommendations?
_______________________________________________ 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 )
On Wed, 20 Nov 2002 17:38:26 -0700, David Bear spoke forth:
I have a script that uses getId to get all structured text documents in a folder. Each of those documents has an added property called 'priority' which is a string type. The value of 'priority' is is used to impose a sort order on the documents. However, I can't figure out how to sort the objects using the the sort method of lists. Any recommendations?
# If the object meta-type is 'ZWiki Page' (I forget for sure) documents = container.objectValues('ZWiki Page') documents.sort(lambda a, b: cmp(a.getProperty('priority'), b.getProperty('priority'))) return documents That should do it for ya. But let me tell you, if you've got more than a couple hundred, you should put them in a ZCatalog and use the search features of the catalog to give you the results. If that were the case, create an index for 'priority', catalog all your ZWiki Pages, and then do: catalog = container.catalog # Or wherever it is query = {} query['sort_on'] = 'priority' documents = catalog.searchResults(query) return documents Hope that helps. :-) -Chris
David Bear writes:
I have a script that uses getId to get all structured text documents in a folder. Each of those documents has an added property called 'priority' which is a string type. The value of 'priority' is is used to impose a sort order on the documents. However, I can't figure out how to sort the objects using the the sort method of lists. Any recommendations? The "sort" function in the "sequence" module, documented in Zope Online Help system...
Dieter
participants (4)
-
Chris Beaven -
Christopher N. Deckard -
David Bear -
Dieter Maurer