Re: [Rest2web-develop] problem with sort order of sections variable
Brought to you by:
mjfoord
From: Michael F. <ar...@vo...> - 2006-11-20 00:13:21
|
martin f krafft wrote: > also sprach Michael Foord <fuz...@vo...> [2006.11.08.1621 +0100]: > >> Nope, no-one has ever asked for it before. What sort of interface would >> you like ? >> > > How about the attribute name of the page variables, e.g. link-title? > > Alternatively, a function could be passed as comparator. using > callable(), you can easily distinguish between the two. :) > Right. 'sections' is an ordered dictionary, ordered by the *sections*. Each section. The 'pages' entry of each section is a list of dictionaries representing each page. This is what we want to order. So the 'sort' method of 'sections' is used to sort the sections, not the pages. What I have done is implemented a new method for 'sections': 'sortpages' This is now in subversion. Docs below. ``sections`` has a method for sorting the pages contained in all the section dictionaries. By default the pages are sorted according to the ``section-pages`` in the restindex. If you don't use section-pages, the ordering is arbitrary. The ``sortpages`` method allows you to sort the pages by ``link-title`` (alphabetical) or pass in a custom function to do the sorting. (The same sort of function you would pass to the Python ``sort`` method of lists.) sections.sortpages(sortorder, section=True) ``sortorder`` can either be the string ``link-title`` or a custom function. By default, calling ``sortpages`` will sort all the sections. Alternatively you can pass in a string (or None), to specify which section to sort. What I haven't done yet is tested this. I'm part way through creating a test case and will probably complete it tomorrow. Comments and bug reports welcomed. :-) Michael http://www.voidspace.org.uk/index2.shtml -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.409 / Virus Database: 268.14.7/538 - Release Date: 18/11/2006 |