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