From: Jani Nikula Date: Sat, 26 Sep 2015 11:37:51 +0000 (+0300) Subject: [PATCH v2] nmbug-status: add support for specifying sort order for each view X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f2eafb9cd719c143d8db9ff2c1ceefe58e2a3191;p=notmuch-archives.git [PATCH v2] nmbug-status: add support for specifying sort order for each view --- diff --git a/94/3065910eb81e974cf427bdbf8cacfd087cce35 b/94/3065910eb81e974cf427bdbf8cacfd087cce35 new file mode 100644 index 000000000..29dc44394 --- /dev/null +++ b/94/3065910eb81e974cf427bdbf8cacfd087cce35 @@ -0,0 +1,108 @@ +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 7FF0B6DE0924 + for ; Sat, 26 Sep 2015 04:38:14 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.534 +X-Spam-Level: +X-Spam-Status: No, score=-0.534 tagged_above=-999 required=5 tests=[AWL=0.186, + RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] + 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 uBdwAqYV6tDG for ; + Sat, 26 Sep 2015 04:38:12 -0700 (PDT) +Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com + [209.85.212.180]) + by arlo.cworth.org (Postfix) with ESMTPS id 3B39D6DE02D2 + for ; Sat, 26 Sep 2015 04:38:12 -0700 (PDT) +Received: by wicfx3 with SMTP id fx3so50812622wic.1 + for ; Sat, 26 Sep 2015 04:38:10 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references; + bh=Y1NJQTCp50DkvqMDMIm54UoMzsqVyIsTPOsOBiooBxE=; + b=mo6w39bf4qWkQEPn2aYod9SOhma2NGn5h2C1llG6U+AOI1hzN5uhKawBvc6plD9cLP + FLLWrdcBa0fXP9tMebKZ7PHTSLXgTRrmHDzXEfNqhqlTfKDFM8ayQhWaWyvq12z48ktz + +ulun7hG7qKQyLupUzBW5G5v4YoW1O4VJs7z+x1g2MnHjvClxg8HkOFhEC5gbMj/2aY3 + 0iXMfIMMAunFVzlRYnv+LGz1x8JQwssqg4oqDRz6sK3d8dgcrXihRAr+L5JlfJOFajXX + H5bUkBcWBMRd7NdyTRMVv9pE4WdnFblYxq07VxhLONGUymAd1QbtymTR2qSzDO+RXasi + wNSA== +X-Gm-Message-State: + ALoCoQkUbfsh5tIHAsD60nwNvdz2OFhwXTLtQir4hdojVjJTVg5f/StS1dCPwIv8pITUY5ogAH9E +X-Received: by 10.180.12.145 with SMTP id y17mr8678987wib.83.1443267490661; + Sat, 26 Sep 2015 04:38:10 -0700 (PDT) +Received: from localhost (mobile-access-bcee63-221.dhcp.inet.fi. + [188.238.99.221]) + by smtp.gmail.com with ESMTPSA id ew2sm7903504wic.20.2015.09.26.04.38.09 + (version=TLSv1/SSLv3 cipher=OTHER); + Sat, 26 Sep 2015 04:38:09 -0700 (PDT) +From: Jani Nikula +To: Tomi Ollila , + "W. Trevor King" +Subject: [PATCH v2] nmbug-status: add support for specifying sort order for + each view +Date: Sat, 26 Sep 2015 14:37:51 +0300 +Message-Id: <1443267471-11829-1-git-send-email-jani@nikula.org> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: +References: +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: Sat, 26 Sep 2015 11:38:14 -0000 + +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 . +--- + 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 +