Browse Source

Support multiple sort options

For dashboards and the change list.

Change-Id: I47236f346d6fa3debd334ccfbfd3da9aea1f3db4
James E. Blair 2 years ago
parent
commit
fca4d23465
2 changed files with 11 additions and 7 deletions
  1. 2
    1
      gertty/config.py
  2. 9
    6
      gertty/db.py

+ 2
- 1
gertty/config.py View File

@@ -54,7 +54,8 @@ class ConfigSchema(object):
54 54
 
55 55
     servers = [server]
56 56
 
57
-    sort_by = v.Any('number', 'updated', 'last-seen')
57
+    _sort_by = v.Any('number', 'updated', 'last-seen')
58
+    sort_by = v.Any(_sort_by, [_sort_by])
58 59
 
59 60
     text_replacement = {'text': v.Any(str,
60 61
                                       {'color': str,

+ 9
- 6
gertty/db.py View File

@@ -881,14 +881,17 @@ class DatabaseSession(object):
881 881
     def getChanges(self, query, unreviewed=False, sort_by='number'):
882 882
         self.database.log.debug("Search query: %s sort: %s" % (query, sort_by))
883 883
         q = self.session().query(Change).filter(self.search.parse(query))
884
+        if not isinstance(sort_by, (list, tuple)):
885
+            sort_by = [sort_by]
884 886
         if unreviewed:
885 887
             q = q.filter(change_table.c.hidden==False, change_table.c.reviewed==False)
886
-        if sort_by == 'updated':
887
-            q = q.order_by(change_table.c.updated)
888
-        elif sort_by == 'last-seen':
889
-            q = q.order_by(change_table.c.last_seen)
890
-        else:
891
-            q = q.order_by(change_table.c.number)
888
+        for s in sort_by:
889
+            if s == 'updated':
890
+                q = q.order_by(change_table.c.updated)
891
+            elif s == 'last-seen':
892
+                q = q.order_by(change_table.c.last_seen)
893
+            elif s == 'number':
894
+                q = q.order_by(change_table.c.number)
892 895
         self.database.log.debug("Search SQL: %s" % q)
893 896
         try:
894 897
             return q.all()

Loading…
Cancel
Save