[PATCH] nmbug-status: add support for specifying sort order for each view

Jani Nikula jani at nikula.org
Fri Apr 3 00:57:12 PDT 2015


Let each view have "sort" key with possible values "oldest-first",
"newest-first", and "unsorted", and sort the results
accordingly. Oldest first remains the default.
---
 devel/nmbug/nmbug-status | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status
index 19dc48abf557..e1abf4db15ba 100755
--- a/devel/nmbug/nmbug-status
+++ b/devel/nmbug/nmbug-status
@@ -156,11 +156,19 @@ class Page (object):
             stream.write(self.footer)
 
     def _write_view(self, database, view, stream):
+        sort = {
+            'oldest-first': notmuch.Query.SORT.OLDEST_FIRST,
+            'newest-first': notmuch.Query.SORT.NEWEST_FIRST,
+            'unsorted': notmuch.Query.SORT.UNSORTED
+        }
         if 'query-string' not in view:
             query = view['query']
             view['query-string'] = ' and '.join(query)
         q = notmuch.Query(database, view['query-string'])
-        q.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
+        if 'sort' in view and view['sort'] in sort:
+            q.set_sort(sort[view['sort']])
+        else:
+            q.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
         threads = self._get_threads(messages=q.search_messages())
         self._write_view_header(view=view, stream=stream)
         self._write_threads(threads=threads, stream=stream)
-- 
2.1.4



More information about the notmuch mailing list