changeset 5903:c3728772c594

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.
author John Rouillard <rouilj@ieee.org>
date Mon, 07 Oct 2019 16:30:47 -0400
parents 4f74b97dddcd
children 2b78e21d7047 76e270b35e63
files CHANGES.txt doc/customizing.txt roundup/cgi/templating.py test/test_templating.py
diffstat 4 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Sun Oct 06 20:23:01 2019 -0400
+++ b/CHANGES.txt	Mon Oct 07 16:30:47 2019 -0400
@@ -177,6 +177,9 @@
   options with IDs and later look up the IDs as *key* of the
   Link/Multilink. Now numeric IDs take precedence -- like they already
   do in the menu method of Link and Multilink.
+- issue2551013: Reversed sorting in hyperdb property wrapper object's
+  sorted() method. Patch by David Sowder, application and doc change
+  by John Rouillard.
 
 2018-07-13 1.6.0
 
--- a/doc/customizing.txt	Sun Oct 06 20:23:01 2019 -0400
+++ b/doc/customizing.txt	Mon Oct 07 16:30:47 2019 -0400
@@ -2701,7 +2701,12 @@
             
                 python:context.files.sorted('creation')
 
-            Will list the files by upload date.
+            Will list the files by upload date. While
+
+	        python:context.files.sorted('creation', reverse=True)
+		
+            Will list the files by upload date in reverse order from
+            the prior example.
 reverse     only on Multilink properties - produce a list of the linked
             items in reverse order
 isset       returns True if the property has been set to a value
--- a/roundup/cgi/templating.py	Sun Oct 06 20:23:01 2019 -0400
+++ b/roundup/cgi/templating.py	Mon Oct 07 16:30:47 2019 -0400
@@ -2310,10 +2310,10 @@
         l.reverse()
         return self.viewableGenerator(l)
 
-    def sorted(self, property):
+    def sorted(self, property, reverse=False):
         """ Return this multilink sorted by the given property """
         value = list(self.__iter__())
-        value.sort(key=lambda a:a[property])
+        value.sort(key=lambda a:a[property], reverse=reverse)
         return value
 
     def __contains__(self, value):
--- a/test/test_templating.py	Sun Oct 06 20:23:01 2019 -0400
+++ b/test/test_templating.py	Mon Oct 07 16:30:47 2019 -0400
@@ -419,6 +419,7 @@
     def __getitem__(self, num):
     def __contains__(self, value):
     def reverse(self):
+    def sorted(self, property, reverse=False):
     def plain(self, escape=0):
     def field(self, size=30, showid=0):
     def menu(self, size=None, height=None, showid=0, additional=[],

Roundup Issue Tracker: http://roundup-tracker.org/