Skip to content

Commit c328b9a

Browse files
author
Johannes Gijsbers
committed
Always sort MultilinkHTMLProperty in the correct order...
...usually alphabetically (feature [SF#790512]). Extract find_sort_key method. Use nested scopes in make_sort_function.
1 parent 39e0d41 commit c328b9a

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

CHANGES.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Feature:
1515
- Existing trackers (ie. live ones) may be used as templates for new
1616
trackers - the TEMPLATE-INFO.txt name entry has the tracker's dir name
1717
appended (so the demo tracker's template name is "classic-demo")
18+
- Always sort MultilinkHTMLProperty in the correct order, usually
19+
alphabetically (sf feature 790512).
1820

1921
Fixed:
2022
- mysql documentation fixed to note requirement of 4.0+ and InnoDB
@@ -55,7 +57,7 @@ Fixed:
5557
- Added note to upgrading doc for detectors fix in 0.6.2
5658
- Added script to help migrating queries from pre-0.6 trackers
5759
- Fixed "documentation" of getnodeids in roundup.hyperdb
58-
- Added flush() to DevNull (sf bug #835365)
60+
- Added flush() to DevNull (sf bug 835365)
5961
- Fixed javascript for help window for only one checkbox case
6062
- Date arithmetic was utterly broken, and has been for a long time.
6163
Date +/- Interval now works, and Date - Date also works (produces

roundup/cgi/templating.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import nested_scopes
2+
13
import sys, cgi, urllib, os, re, os.path, time, errno, mimetypes
24

35
from 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+
13971395
def 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

Comments
 (0)