Skip to content

Commit 11cad1b

Browse files
committed
Add reverse option to hyperdb property wrapper by David Sowder
issue2551013: Reversed sorting in hyperdb property wrapper object's sorted() method. Patch by David Sowder, application and doc change by John Rouillard.
1 parent b8f134f commit 11cad1b

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ Fixed:
177177
options with IDs and later look up the IDs as *key* of the
178178
Link/Multilink. Now numeric IDs take precedence -- like they already
179179
do in the menu method of Link and Multilink.
180+
- issue2551013: Reversed sorting in hyperdb property wrapper object's
181+
sorted() method. Patch by David Sowder, application and doc change
182+
by John Rouillard.
180183

181184
2018-07-13 1.6.0
182185

doc/customizing.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,12 @@ sorted only on Multilink properties - produce a list of the linked
27012701

27022702
python:context.files.sorted('creation')
27032703

2704-
Will list the files by upload date.
2704+
Will list the files by upload date. While
2705+
2706+
python:context.files.sorted('creation', reverse=True)
2707+
2708+
Will list the files by upload date in reverse order from
2709+
the prior example.
27052710
reverse only on Multilink properties - produce a list of the linked
27062711
items in reverse order
27072712
isset returns True if the property has been set to a value

roundup/cgi/templating.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,10 +2310,10 @@ def reverse(self):
23102310
l.reverse()
23112311
return self.viewableGenerator(l)
23122312

2313-
def sorted(self, property):
2313+
def sorted(self, property, reverse=False):
23142314
""" Return this multilink sorted by the given property """
23152315
value = list(self.__iter__())
2316-
value.sort(key=lambda a:a[property])
2316+
value.sort(key=lambda a:a[property], reverse=reverse)
23172317
return value
23182318

23192319
def __contains__(self, value):

test/test_templating.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ def __getattr__(self, attr):
419419
def __getitem__(self, num):
420420
def __contains__(self, value):
421421
def reverse(self):
422+
def sorted(self, property, reverse=False):
422423
def plain(self, escape=0):
423424
def field(self, size=30, showid=0):
424425
def menu(self, size=None, height=None, showid=0, additional=[],

0 commit comments

Comments
 (0)