From d231708471e5431f70e97223d245cf70cb3c7bd7 Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Mon, 6 Apr 2015 19:48:09 +0300 Subject: [PATCH] Re: [PATCH] nmbug-status: add support for specifying sort order for each view --- 5c/482bc88ab3b15ac30c853b4e41dee6a4d28c24 | 104 ++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 5c/482bc88ab3b15ac30c853b4e41dee6a4d28c24 diff --git a/5c/482bc88ab3b15ac30c853b4e41dee6a4d28c24 b/5c/482bc88ab3b15ac30c853b4e41dee6a4d28c24 new file mode 100644 index 000000000..ff970b963 --- /dev/null +++ b/5c/482bc88ab3b15ac30c853b4e41dee6a4d28c24 @@ -0,0 +1,104 @@ +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 59A066DE1A5E + for ; Mon, 6 Apr 2015 09:48:37 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 1.202 +X-Spam-Level: * +X-Spam-Status: No, score=1.202 tagged_above=-999 required=5 tests=[AWL=0.550, + SPF_NEUTRAL=0.652] 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 1Umx1Eyd6W-W for ; + Mon, 6 Apr 2015 09:48:33 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by arlo.cworth.org (Postfix) with ESMTP id 96A5A6DE1A34 + for ; Mon, 6 Apr 2015 09:48:33 -0700 (PDT) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id E347910019F; + Mon, 6 Apr 2015 19:48:09 +0300 (EEST) +From: Tomi Ollila +To: "W. Trevor King" +Subject: Re: [PATCH] nmbug-status: add support for specifying sort order for + each view +In-Reply-To: <20150406155659.GS10467@odin.tremily.us> +References: <20150406155659.GS10467@odin.tremily.us> +User-Agent: Notmuch/0.19+107~gab55bdb (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +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:48:37 -0000 + +On Mon, Apr 06 2015, "W. Trevor King" wrote: + +> 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 = { +>> + '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 = view.get('sort', 'oldest-first') +> sort_attribute = sort_key.upper().replace('-', '_')) +> try: +> sort = 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. + +I like how this suggestion looks like. + +Tomi + +> +>> - 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 +> +> -- +> 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 -- 2.26.2