[PATCH v2] nmbug-status: add support for specifying sort order for each view
authorJani Nikula <jani@nikula.org>
Sat, 26 Sep 2015 11:37:51 +0000 (14:37 +0300)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:49:38 +0000 (14:49 -0700)
94/3065910eb81e974cf427bdbf8cacfd087cce35 [new file with mode: 0644]

diff --git a/94/3065910eb81e974cf427bdbf8cacfd087cce35 b/94/3065910eb81e974cf427bdbf8cacfd087cce35
new file mode 100644 (file)
index 0000000..29dc443
--- /dev/null
@@ -0,0 +1,108 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 7FF0B6DE0924\r
+ for <notmuch@notmuchmail.org>; Sat, 26 Sep 2015 04:38:14 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.534\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.534 tagged_above=-999 required=5 tests=[AWL=0.186,\r
+  RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id uBdwAqYV6tDG for <notmuch@notmuchmail.org>;\r
+ Sat, 26 Sep 2015 04:38:12 -0700 (PDT)\r
+Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com\r
+ [209.85.212.180])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 3B39D6DE02D2\r
+ for <notmuch@notmuchmail.org>; Sat, 26 Sep 2015 04:38:12 -0700 (PDT)\r
+Received: by wicfx3 with SMTP id fx3so50812622wic.1\r
+ for <notmuch@notmuchmail.org>; Sat, 26 Sep 2015 04:38:10 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+ :references;\r
+ bh=Y1NJQTCp50DkvqMDMIm54UoMzsqVyIsTPOsOBiooBxE=;\r
+ b=mo6w39bf4qWkQEPn2aYod9SOhma2NGn5h2C1llG6U+AOI1hzN5uhKawBvc6plD9cLP\r
+ FLLWrdcBa0fXP9tMebKZ7PHTSLXgTRrmHDzXEfNqhqlTfKDFM8ayQhWaWyvq12z48ktz\r
+ +ulun7hG7qKQyLupUzBW5G5v4YoW1O4VJs7z+x1g2MnHjvClxg8HkOFhEC5gbMj/2aY3\r
+ 0iXMfIMMAunFVzlRYnv+LGz1x8JQwssqg4oqDRz6sK3d8dgcrXihRAr+L5JlfJOFajXX\r
+ H5bUkBcWBMRd7NdyTRMVv9pE4WdnFblYxq07VxhLONGUymAd1QbtymTR2qSzDO+RXasi\r
+ wNSA==\r
+X-Gm-Message-State:\r
+ ALoCoQkUbfsh5tIHAsD60nwNvdz2OFhwXTLtQir4hdojVjJTVg5f/StS1dCPwIv8pITUY5ogAH9E\r
+X-Received: by 10.180.12.145 with SMTP id y17mr8678987wib.83.1443267490661;\r
+ Sat, 26 Sep 2015 04:38:10 -0700 (PDT)\r
+Received: from localhost (mobile-access-bcee63-221.dhcp.inet.fi.\r
+ [188.238.99.221])\r
+ by smtp.gmail.com with ESMTPSA id ew2sm7903504wic.20.2015.09.26.04.38.09\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Sat, 26 Sep 2015 04:38:09 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Tomi Ollila <tomi.ollila@iki.fi>,\r
+       "W. Trevor King" <wking@tremily.us>\r
+Subject: [PATCH v2] nmbug-status: add support for specifying sort order for\r
+ each view\r
+Date: Sat, 26 Sep 2015 14:37:51 +0300\r
+Message-Id: <1443267471-11829-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <m2r3rx9p9y.fsf@guru.guru-group.fi>\r
+References: <m2r3rx9p9y.fsf@guru.guru-group.fi>\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 26 Sep 2015 11:38:14 -0000\r
+\r
+Let each view have a "sort" key, typically used with values\r
+"oldest-first" or "newest-first" (although all values in Query.SORT\r
+are accepted), and sort the results accordingly. Oldest first remains\r
+the default.\r
+\r
+The dynamic approach of mapping sort values is as suggested by\r
+W. Trevor King <wking@tremily.us>.\r
+---\r
+ devel/nmbug/nmbug-status | 11 ++++++++++-\r
+ 1 file changed, 10 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status\r
+index e845c2a5c8f7..a289798e3cc1 100755\r
+--- a/devel/nmbug/nmbug-status\r
++++ b/devel/nmbug/nmbug-status\r
+@@ -156,11 +156,20 @@ class Page (object):\r
+             stream.write(self.footer)\r
\r
+     def _write_view(self, database, view, stream):\r
++        # sort order, default to oldest-first\r
++        sort_key = view.get('sort', 'oldest-first')\r
++        # dynamically accept all values in Query.SORT\r
++        sort_attribute = sort_key.upper().replace('-', '_')\r
++        try:\r
++            sort = getattr(notmuch.Query.SORT, sort_attribute)\r
++        except AttributeError:\r
++            raise ConfigError('Invalid sort setting for {}: {!r}'.format(\r
++                view['title'], sort_key))\r
+         if 'query-string' not in view:\r
+             query = view['query']\r
+             view['query-string'] = ' and '.join(query)\r
+         q = notmuch.Query(database, view['query-string'])\r
+-        q.set_sort(notmuch.Query.SORT.OLDEST_FIRST)\r
++        q.set_sort(sort)\r
+         threads = self._get_threads(messages=q.search_messages())\r
+         self._write_view_header(view=view, stream=stream)\r
+         self._write_threads(threads=threads, stream=stream)\r
+-- \r
+2.1.4\r
+\r