From: Jani Nikula Date: Sat, 26 Sep 2015 11:37:51 +0000 (+0300) Subject: nmbug-status: add support for specifying sort order for each view X-Git-Tag: 0.21_rc0~21 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=8b35b8f71aec56232a3d305aff6cf315bf31331e 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 . --- 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)