Re: [PATCH] nmbug-status: add support for specifying sort order for each view
authorW. Trevor King <wking@tremily.us>
Mon, 6 Apr 2015 15:56:59 +0000 (08:56 +1700)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:48:44 +0000 (14:48 -0700)
52/708c3c624cadb9aa51ce306ed34472ff899030 [new file with mode: 0644]

diff --git a/52/708c3c624cadb9aa51ce306ed34472ff899030 b/52/708c3c624cadb9aa51ce306ed34472ff899030
new file mode 100644 (file)
index 0000000..36c3c3c
--- /dev/null
@@ -0,0 +1,152 @@
+Return-Path: <wking@tremily.us>\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 BCD826DE1A16\r
+ for <notmuch@notmuchmail.org>; Mon,  6 Apr 2015 09:07:17 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.757\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.757 tagged_above=-999 required=5 tests=[AWL=-0.116,\r
+  DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FAKE_REPLY_C=0.001,\r
+ RCVD_IN_DNSWL_NONE=-0.0001, SPF_SOFTFAIL=0.972] 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 2HqfSOYx5TCt for <notmuch@notmuchmail.org>;\r
+ Mon,  6 Apr 2015 09:07:13 -0700 (PDT)\r
+X-Greylist: delayed 490 seconds by postgrey-1.35 at arlo;\r
+ Mon, 06 Apr 2015 09:07:13 PDT\r
+Received: from resqmta-po-08v.sys.comcast.net (resqmta-po-08v.sys.comcast.net\r
+ [96.114.154.167])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id A08D96DE1A1B\r
+ for <notmuch@notmuchmail.org>; Mon,  6 Apr 2015 09:07:13 -0700 (PDT)\r
+Received: from resomta-po-02v.sys.comcast.net ([96.114.154.226])\r
+ by resqmta-po-08v.sys.comcast.net with comcast\r
+ id Cfyk1q0074tLnxL01fz1ex; Mon, 06 Apr 2015 15:59:01 +0000\r
+Received: from odin.tremily.us ([67.168.81.176])\r
+ by resomta-po-02v.sys.comcast.net with comcast\r
+ id Cfx01q0043oF5yT01fx008; Mon, 06 Apr 2015 15:57:01 +0000\r
+Received: by odin.tremily.us (Postfix, from userid 1000)\r
+ id 4D421174D3B4; Mon,  6 Apr 2015 08:56:59 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tremily.us; s=odin;\r
+ t=1428335819; bh=kg12UuuvoFuZLm6HC5kknXYD/j7PrFNYum6PBx5xlZ8=;\r
+ h=Date:From:To:Cc:Subject:In-Reply-To;\r
+ b=FQOGApbdyy2dNL6pmrehe6GdhPUNUIY3tpBw+qstrawbWREyKB0tCu9KXh2yehqZ/\r
+ wbPNP3/MQTIJT6d2zPBpDsWVP7XLhsrhfublqWBrjMhZbGR96yEiOAnSFaeFFt0ewW\r
+ KVaXUAcoI5kLen3nOYK7flhj946sji3s45lOB+yg=\r
+Date: Mon, 6 Apr 2015 08:56:59 -0700\r
+From: "W. Trevor King" <wking@tremily.us>\r
+To: Tomi Ollila <tomi.ollila@iki.fi>\r
+Subject: Re: [PATCH] nmbug-status: add support for specifying sort order for\r
+ each view\r
+Message-ID: <20150406155659.GS10467@odin.tremily.us>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; micalg=pgp-sha1;\r
+ protocol="application/pgp-signature"; boundary="gXx2FYK2AghGE4Yq"\r
+Content-Disposition: inline\r
+In-Reply-To: <1428047832-14922-1-git-send-email-jani@nikula.org>\r
+OpenPGP: id=39A2F3FA2AB17E5D8764F388FC29BDCDF15F5BE8;\r
+ url=http://tremily.us/pubkey.txt\r
+User-Agent: Mutt/1.5.23 (2014-03-12)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net;\r
+ s=q20140121; t=1428335941;\r
+ bh=VMM0xyuzE/V8M/dUbqCAgW54k5rsLu8QAMlVi9jHOMI=;\r
+ h=Received:Received:Received:Date:From:To:Subject:Message-ID:\r
+ MIME-Version:Content-Type;\r
+ b=t7ldgERgNw+ZDM1EB7+IZ7PGcHubeMm+tdNL+mjcO3yI8t0Gj9XICwESMpurt618m\r
+ DVTr7cxaRE6Cwd8i5OEHWZkOo65/di9NkhXuTwDJactlEMR+1hDLLrcY/luppTuVxK\r
+ dC2EHXKIEujO20U1rD2iNrpPdM7L95+zAYQ731si9EAQtXFG4ua373K9m1K4PBMARt\r
+ i3/5pZ6Rhv4C8MRcT/UPGckqzxYcjmA/URSFcRYE7y1AfuG3/lcv1T5wV7l/Q4GSRt\r
+ 4YtePf0+dr4rTwWo1glA2V7MDlaKE8pr4lFxAGRzmi28dlIFFHEQHxVmZT9YzP3ZS2\r
+ sI7u8g7xCW9pQ==\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: Mon, 06 Apr 2015 16:07:17 -0000\r
+\r
+\r
+--gXx2FYK2AghGE4Yq\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+On Fri, Apr 03 2015, Jani Nikula <jani@nikula.org> wrote:\r
+> Let each view have "sort" key with possible values "oldest-first",\r
+> "newest-first", and "unsorted", and sort the results\r
+> accordingly. Oldest first remains the default.\r
+\r
+I like it, but have a few suggestions to tweak the implementation.\r
+\r
+>      def _write_view(self, database, view, stream):\r
+> +        sort =3D {\r
+> +            'oldest-first': notmuch.Query.SORT.OLDEST_FIRST,\r
+> +            'newest-first': notmuch.Query.SORT.NEWEST_FIRST,\r
+> +            'unsorted': notmuch.Query.SORT.UNSORTED\r
+> +        }\r
+\r
+I'd rather have this mapping defined in a global variable\r
+(_SORT_TERMS?) or a class-wide attribute (Page.sort_terms?).\r
+Alternatively, you could do something dynamic like:\r
+\r
+       sort_key =3D view.get('sort', 'oldest-first')\r
+  sort_attribute =3D sort_key.upper().replace('-', '_'))\r
+  try:\r
+      sort =3D getattr(notmuch.Query.SORT, sort_attribute)\r
+  except AttributeError:\r
+      raise ConfigError('Invalid setting for {}: {!r}'.format(\r
+          view['title'], sort_key))\r
+\r
+which would automatically keep the implementation in sync with the\r
+available values in notmuch.Query.SORT.\r
+\r
+> -        q.set_sort(notmuch.Query.SORT.OLDEST_FIRST)\r
+> +        if 'sort' in view and view['sort'] in sort:\r
+> +            q.set_sort(sort[view['sort']])\r
+> +        else:\r
+> +            q.set_sort(notmuch.Query.SORT.OLDEST_FIRST)\r
+\r
+Instead of silently falling back to oldest-first if the requested\r
+sort-key isn't available, I think we should be raising ConfigError so\r
+the user knows they need to update their config.\r
+\r
+Cheers,\r
+Trevor\r
+\r
+--=20\r
+This email may be signed or encrypted with GnuPG (http://www.gnupg.org).\r
+For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy\r
+\r
+--gXx2FYK2AghGE4Yq\r
+Content-Type: application/pgp-signature; name="signature.asc"\r
+Content-Description: OpenPGP digital signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v2\r
+\r
+iQIcBAEBAgAGBQJVIqzIAAoJEG8/JgBt8ol8nuoP/1cPjZzGgmqy9ZtMts7dOCrC\r
+C08gsUmiqgK6NWhAVnKzR4Fea38aUBSLnFcmQViU/XEfa3OwiBGCM2CxBbeUTE0V\r
+3THjRdlVSiz36fIsrvaSP51wAF6DU6Qwaeb8/COPEaNm8GnsfwzQau1yjcOYJPij\r
+HyI3BrOvxNd2y/6nJTjtbtoxt+FfrnhPTlA9gLlZEDDOCFTJx5p4ACDcxyoqlfXZ\r
+B+4AbSyIiOXmjOhs3zULmZgp4RMYIMTZTcE8HnaXbkLZHsCTPZjyO7X1OhVRe59i\r
+Hu/NyvU5eeFopfBw6EuW81wYp14piKJRiZdzDWWj0Vno+duDeMJBna25yaVwcVmA\r
+1iRicnJ8BVEEAhhBokfCd74DKE8TTha6H0V5+majN4LwohuYlIoh4qxDEfAILeKC\r
+uZv8j7gaqS2yeLNxARoxy0H5v5wVeh8TIvky1j/td1oG96XXC/pDX7N/tEBOBGDi\r
+8PNTdZ5SHMDOnmaD3FTW1Ivq0Mkip3Rrtl1yC/hwfy1Ie04SN8C6YGiGeMFl6CRi\r
+RlE2TMoz8+lqMqQ2BhtmrMp+FE59t4eT/Xl/lsPV/mlnjcoe67OMDOTOo9UdZIdE\r
+qGVCg+Nxr45R7LA1eJm6P0d0Ai9iieur3dnQW9nLmbwEzvf/ERracZChaf1zgp3d\r
+LArbR2GO8RY+xRTM7RFl\r
+=1hYa\r
+-----END PGP SIGNATURE-----\r
+\r
+--gXx2FYK2AghGE4Yq--\r