unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] nmbug-status: add support for specifying sort order for each view
@ 2015-04-03  7:57 Jani Nikula
  2015-04-06 11:43 ` Tomi Ollila
  2015-04-06 15:56 ` W. Trevor King
  0 siblings, 2 replies; 8+ messages in thread
From: Jani Nikula @ 2015-04-03  7:57 UTC (permalink / raw)
  To: notmuch

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.
---
 devel/nmbug/nmbug-status | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status
index 19dc48abf557..e1abf4db15ba 100755
--- a/devel/nmbug/nmbug-status
+++ b/devel/nmbug/nmbug-status
@@ -156,11 +156,19 @@ class Page (object):
             stream.write(self.footer)
 
     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
+        }
         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)
+        if 'sort' in view and view['sort'] in sort:
+            q.set_sort(sort[view['sort']])
+        else:
+            q.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
         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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] nmbug-status: add support for specifying sort order for each view
  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
  1 sibling, 0 replies; 8+ messages in thread
From: Tomi Ollila @ 2015-04-06 11:43 UTC (permalink / raw)
  To: Jani Nikula, notmuch

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.
> ---

lgtm.

Tomi

>  devel/nmbug/nmbug-status | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status
> index 19dc48abf557..e1abf4db15ba 100755
> --- a/devel/nmbug/nmbug-status
> +++ b/devel/nmbug/nmbug-status
> @@ -156,11 +156,19 @@ class Page (object):
>              stream.write(self.footer)
>  
>      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
> +        }
>          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)
> +        if 'sort' in view and view['sort'] in sort:
> +            q.set_sort(sort[view['sort']])
> +        else:
> +            q.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
>          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
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nmbug-status: add support for specifying sort order for each view
  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
  1 sibling, 1 reply; 8+ messages in thread
From: W. Trevor King @ 2015-04-06 15:56 UTC (permalink / raw)
  To: Tomi Ollila; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 1772 bytes --]

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.

> -        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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nmbug-status: add support for specifying sort order for each view
  2015-04-06 15:56 ` W. Trevor King
@ 2015-04-06 16:48   ` Tomi Ollila
  2015-09-26 11:37     ` [PATCH v2] " Jani Nikula
  0 siblings, 1 reply; 8+ messages in thread
From: Tomi Ollila @ 2015-04-06 16:48 UTC (permalink / raw)
  To: W. Trevor King; +Cc: notmuch

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2] nmbug-status: add support for specifying sort order for each view
  2015-04-06 16:48   ` Tomi Ollila
@ 2015-09-26 11:37     ` Jani Nikula
  2015-09-26 18:47       ` W. Trevor King
  2015-09-29 11:27       ` David Bremner
  0 siblings, 2 replies; 8+ messages in thread
From: Jani Nikula @ 2015-09-26 11:37 UTC (permalink / raw)
  To: Tomi Ollila, W. Trevor King; +Cc: notmuch

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 <wking@tremily.us>.
---
 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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] nmbug-status: add support for specifying sort order for each view
  2015-09-26 11:37     ` [PATCH v2] " Jani Nikula
@ 2015-09-26 18:47       ` W. Trevor King
  2015-09-29 11:27       ` David Bremner
  1 sibling, 0 replies; 8+ messages in thread
From: W. Trevor King @ 2015-09-26 18:47 UTC (permalink / raw)
  To: Jani Nikula; +Cc: Tomi Ollila, notmuch

[-- Attachment #1: Type: text/plain, Size: 198 bytes --]

Looks good to me ;).

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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] nmbug-status: add support for specifying sort order for each view
  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
  1 sibling, 1 reply; 8+ messages in thread
From: David Bremner @ 2015-09-29 11:27 UTC (permalink / raw)
  To: Jani Nikula, Tomi Ollila, W. Trevor King; +Cc: notmuch

Jani Nikula <jani@nikula.org> writes:

> 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.

pushed.

d

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2] nmbug-status: add support for specifying sort order for each view
  2015-09-29 11:27       ` David Bremner
@ 2015-09-29 18:58         ` Tomi Ollila
  0 siblings, 0 replies; 8+ messages in thread
From: Tomi Ollila @ 2015-09-29 18:58 UTC (permalink / raw)
  To: David Bremner, Jani Nikula, W. Trevor King; +Cc: notmuch

On Tue, Sep 29 2015, David Bremner <david@tethera.net> wrote:

> Jani Nikula <jani@nikula.org> writes:
>
>> 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.
>
> pushed.

when can we expect nmbug status page update ? :D

>
> d

Tomi

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-09-29 18:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).