From 8b35b8f71aec56232a3d305aff6cf315bf31331e Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Sat, 26 Sep 2015 14:37:51 +0300 Subject: [PATCH] nmbug-status: add support for specifying sort order for each view Let each view have a "sort" key, typically used with values "oldest-first" or "newest-first" (although all values in Query.SORT are accepted), and sort the results accordingly. Oldest first remains the default. The dynamic approach of mapping sort values is as suggested by W. Trevor King . --- devel/nmbug/nmbug-status | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status index e845c2a5..a289798e 100755 --- a/devel/nmbug/nmbug-status +++ b/devel/nmbug/nmbug-status @@ -156,11 +156,20 @@ class Page (object): stream.write(self.footer) def _write_view(self, database, view, stream): + # sort order, default to oldest-first + sort_key = view.get('sort', 'oldest-first') + # dynamically accept all values in Query.SORT + sort_attribute = sort_key.upper().replace('-', '_') + try: + sort = getattr(notmuch.Query.SORT, sort_attribute) + except AttributeError: + raise ConfigError('Invalid sort setting for {}: {!r}'.format( + view['title'], sort_key)) 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) + q.set_sort(sort) threads = self._get_threads(messages=q.search_messages()) self._write_view_header(view=view, stream=stream) self._write_threads(threads=threads, stream=stream)