Mercurial > p > roundup > code
diff roundup/cgi/templating.py @ 1931:f1e5e5115c29
Always sort MultilinkHTMLProperty in the correct order...
...usually alphabetically (feature [SF#790512]).
Extract find_sort_key method.
Use nested scopes in make_sort_function.
| author | Johannes Gijsbers <jlgijsbers@users.sourceforge.net> |
|---|---|
| date | Thu, 20 Nov 2003 15:20:21 +0000 |
| parents | 9bf9cf980656 |
| children | cd7af2579d20 |
line wrap: on
line diff
--- a/roundup/cgi/templating.py Wed Nov 19 22:53:15 2003 +0000 +++ b/roundup/cgi/templating.py Thu Nov 20 15:20:21 2003 +0000 @@ -1,3 +1,5 @@ +from __future__ import nested_scopes + import sys, cgi, urllib, os, re, os.path, time, errno, mimetypes from roundup import hyperdb, date, rcsv @@ -1193,9 +1195,6 @@ ''' value = self._value - # sort function - sortfunc = make_sort_function(self._db, self._prop.classname) - linkcl = self._db.getclass(self._prop.classname) l = ['<select name="%s">'%self._formname] k = linkcl.labelprop(1) @@ -1250,6 +1249,11 @@ Also be iterable, returning a wrapper object like the Link case for each entry in the multilink. ''' + def __init__(self, *args, **kwargs): + HTMLProperty.__init__(self, *args, **kwargs) + if self._value: + self._value.sort(make_sort_function(self._db, self._prop.classname)) + def __len__(self): ''' length of the multilink ''' return len(self._value) @@ -1302,11 +1306,8 @@ def field(self, size=30, showid=0): ''' Render a form edit field for the property ''' - sortfunc = make_sort_function(self._db, self._prop.classname) linkcl = self._db.getclass(self._prop.classname) value = self._value[:] - if value: - value.sort(sortfunc) # map the id to the label property if not linkcl.getkey(): showid=1 @@ -1322,15 +1323,9 @@ ''' value = self._value - # sort function - sortfunc = make_sort_function(self._db, self._prop.classname) - linkcl = self._db.getclass(self._prop.classname) - if linkcl.getprops().has_key('order'): - sort_on = ('+', 'order') - else: - sort_on = ('+', linkcl.labelprop()) - options = linkcl.filter(None, conditions, sort_on, (None,None)) + sort_on = ('+', find_sort_key(linkcl)) + options = linkcl.filter(None, conditions, sort_on) height = height or min(len(options), 7) l = ['<select multiple name="%s" size="%s">'%(self._formname, height)] k = linkcl.labelprop(1) @@ -1386,14 +1381,17 @@ '''Make a sort function for a given class ''' linkcl = db.getclass(classname) - if linkcl.getprops().has_key('order'): - sort_on = 'order' - else: - sort_on = linkcl.labelprop() - def sortfunc(a, b, linkcl=linkcl, sort_on=sort_on): + sort_on = find_sort_key(linkcl) + def sortfunc(a, b): return cmp(linkcl.get(a, sort_on), linkcl.get(b, sort_on)) return sortfunc +def find_sort_key(linkcl): + if linkcl.getprops().has_key('order'): + return 'order' + else: + return linkcl.labelprop() + def handleListCGIValue(value): ''' Value is either a single item or a list of items. Each item has a .value that we're actually interested in.
