unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: "W. Trevor King" <wking@tremily.us>
Cc: notmuch@notmuchmail.org
Subject: Re: [PATCH] nmbug-status: add support for specifying sort order for each view
Date: Mon, 06 Apr 2015 19:48:09 +0300	[thread overview]
Message-ID: <m2r3rx9p9y.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <20150406155659.GS10467@odin.tremily.us>

On Mon, Apr 06 2015, "W. Trevor King" <wking@tremily.us> wrote:

> On Fri, Apr 03 2015, Jani Nikula <jani@nikula.org> 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

  reply	other threads:[~2015-04-06 16:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-03  7:57 [PATCH] nmbug-status: add support for specifying sort order for each view Jani Nikula
2015-04-06 11:43 ` Tomi Ollila
2015-04-06 15:56 ` W. Trevor King
2015-04-06 16:48   ` Tomi Ollila [this message]
2015-09-26 11:37     ` [PATCH v2] " Jani Nikula
2015-09-26 18:47       ` W. Trevor King
2015-09-29 11:27       ` David Bremner
2015-09-29 18:58         ` Tomi Ollila

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2r3rx9p9y.fsf@guru.guru-group.fi \
    --to=tomi.ollila@iki.fi \
    --cc=notmuch@notmuchmail.org \
    --cc=wking@tremily.us \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).