unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: Tomi Ollila <tomi.ollila@iki.fi>, "W. Trevor King" <wking@tremily.us>
Cc: notmuch@notmuchmail.org
Subject: [PATCH v2] nmbug-status: add support for specifying sort order for each view
Date: Sat, 26 Sep 2015 14:37:51 +0300	[thread overview]
Message-ID: <1443267471-11829-1-git-send-email-jani@nikula.org> (raw)
In-Reply-To: <m2r3rx9p9y.fsf@guru.guru-group.fi>

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 <wking@tremily.us>.
---
 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 e845c2a5c8f7..a289798e3cc1 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)
-- 
2.1.4

  reply	other threads:[~2015-09-26 11:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-03  7:57 [PATCH] nmbug-status: add support for specifying sort order for each view Jani Nikula
2015-04-06 11:43 ` Tomi Ollila
2015-04-06 15:56 ` W. Trevor King
2015-04-06 16:48   ` Tomi Ollila
2015-09-26 11:37     ` Jani Nikula [this message]
2015-09-26 18:47       ` [PATCH v2] " W. Trevor King
2015-09-29 11:27       ` David Bremner
2015-09-29 18:58         ` Tomi Ollila

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443267471-11829-1-git-send-email-jani@nikula.org \
    --to=jani@nikula.org \
    --cc=notmuch@notmuchmail.org \
    --cc=tomi.ollila@iki.fi \
    --cc=wking@tremily.us \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).