Skip to content

Commit 34ed808

Browse files
committed
Fix issue2551122 (MultilinkHTMLProperty sorted method issue)
The sorted method of MultilinkHTMLProperty does a string sort even if the property is an integer. Fixed so that the orderprop for the linked class is used.
1 parent c11001d commit 34ed808

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ Fixed:
116116
signature. Without these upgrades, ssl mode won't start. Note this
117117
exposes other issue with roundup-server operating as an SSL
118118
endpoint. See issue2551138 and issue2551137.
119+
- issue2551122 - sorted method of MultilinkHTMLProperty does a string
120+
sort even if the property is an integer. Fixed so that the orderprop
121+
for the linked class is used. (John Rouillard, reported by Nagy Gabor)
119122

120123
Features:
121124
- issue2550522 - Add 'filter' command to command-line

doc/customizing.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3305,7 +3305,10 @@ sorted only on Multilink properties - produce a list of the linked
33053305
creation date at the start of the list. The default for
33063306
``NoneFirst`` is False so these files will sort at the end
33073307
by default. (Note creation date is never unset, but you
3308-
get the idea.)
3308+
get the idea.) If you combine NoneFirst with
3309+
``reverse=True`` the meaning of NoneFirst is inverted:
3310+
True sorts None/unset at the end and False sorts at the
3311+
beginning.
33093312
reverse only on Multilink properties - produce a list of the linked
33103313
items in reverse order
33113314
isset returns True if the property has been set to a value

roundup/cgi/templating.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,19 +2624,31 @@ def sorted(self, property, reverse=False, NoneFirst=False):
26242624
# 0 to sort to sort None first
26252625
# 1 is used to sort the integer values.
26262626
NoneCode = (2,0)[NoneFirst]
2627+
2628+
value = list(self.__iter__())
2629+
2630+
# determine orderprop for property.
2631+
if value:
2632+
orderprop = value[0]._db.getclass(property).orderprop()
2633+
else: # return empty list, nothing to sort.
2634+
return value
2635+
26272636
def keyfunc(v):
26282637
# Return tuples made of (group order (int), base python
26292638
# type) to sort function.
26302639
# Do not return v[property] as that returns an HTMLProperty
26312640
# type/subtype that throws an exception when sorting
26322641
# python type (int. str ...) against None.
2633-
val = v[property]._value
2634-
if val:
2635-
return (1, val) # val should be base python type
2636-
elif val is None:
2642+
prop = v[property]
2643+
if not prop._value:
26372644
return (NoneCode, None)
26382645

2639-
value = list(self.__iter__())
2646+
val = prop[orderprop]._value
2647+
2648+
if val is None: # verify orderprop is set to a value
2649+
return (NoneCode, None)
2650+
return (1, val) # val should be base python type
2651+
26402652
value.sort(key=keyfunc, reverse=reverse)
26412653
return value
26422654

0 commit comments

Comments
 (0)