1+ from __future__ import nested_scopes
2+
13import sys , cgi , urllib , os , re , os .path , time , errno , mimetypes
24
35from roundup import hyperdb , date , rcsv
@@ -1193,9 +1195,6 @@ def menu(self, size=None, height=None, showid=0, additional=[],
11931195 '''
11941196 value = self ._value
11951197
1196- # sort function
1197- sortfunc = make_sort_function (self ._db , self ._prop .classname )
1198-
11991198 linkcl = self ._db .getclass (self ._prop .classname )
12001199 l = ['<select name="%s">' % self ._formname ]
12011200 k = linkcl .labelprop (1 )
@@ -1250,6 +1249,11 @@ class MultilinkHTMLProperty(HTMLProperty):
12501249 Also be iterable, returning a wrapper object like the Link case for
12511250 each entry in the multilink.
12521251 '''
1252+ def __init__ (self , * args , ** kwargs ):
1253+ HTMLProperty .__init__ (self , * args , ** kwargs )
1254+ if self ._value :
1255+ self ._value .sort (make_sort_function (self ._db , self ._prop .classname ))
1256+
12531257 def __len__ (self ):
12541258 ''' length of the multilink '''
12551259 return len (self ._value )
@@ -1302,11 +1306,8 @@ def plain(self, escape=0):
13021306 def field (self , size = 30 , showid = 0 ):
13031307 ''' Render a form edit field for the property
13041308 '''
1305- sortfunc = make_sort_function (self ._db , self ._prop .classname )
13061309 linkcl = self ._db .getclass (self ._prop .classname )
13071310 value = self ._value [:]
1308- if value :
1309- value .sort (sortfunc )
13101311 # map the id to the label property
13111312 if not linkcl .getkey ():
13121313 showid = 1
@@ -1322,15 +1323,9 @@ def menu(self, size=None, height=None, showid=0, additional=[],
13221323 '''
13231324 value = self ._value
13241325
1325- # sort function
1326- sortfunc = make_sort_function (self ._db , self ._prop .classname )
1327-
13281326 linkcl = self ._db .getclass (self ._prop .classname )
1329- if linkcl .getprops ().has_key ('order' ):
1330- sort_on = ('+' , 'order' )
1331- else :
1332- sort_on = ('+' , linkcl .labelprop ())
1333- options = linkcl .filter (None , conditions , sort_on , (None ,None ))
1327+ sort_on = ('+' , find_sort_key (linkcl ))
1328+ options = linkcl .filter (None , conditions , sort_on )
13341329 height = height or min (len (options ), 7 )
13351330 l = ['<select multiple name="%s" size="%s">' % (self ._formname , height )]
13361331 k = linkcl .labelprop (1 )
@@ -1386,14 +1381,17 @@ def make_sort_function(db, classname):
13861381 '''Make a sort function for a given class
13871382 '''
13881383 linkcl = db .getclass (classname )
1389- if linkcl .getprops ().has_key ('order' ):
1390- sort_on = 'order'
1391- else :
1392- sort_on = linkcl .labelprop ()
1393- def sortfunc (a , b , linkcl = linkcl , sort_on = sort_on ):
1384+ sort_on = find_sort_key (linkcl )
1385+ def sortfunc (a , b ):
13941386 return cmp (linkcl .get (a , sort_on ), linkcl .get (b , sort_on ))
13951387 return sortfunc
13961388
1389+ def find_sort_key (linkcl ):
1390+ if linkcl .getprops ().has_key ('order' ):
1391+ return 'order'
1392+ else :
1393+ return linkcl .labelprop ()
1394+
13971395def handleListCGIValue (value ):
13981396 ''' Value is either a single item or a list of items. Each item has a
13991397 .value that we're actually interested in.
0 commit comments