From c4c5723a61f170cb5945b49ce18b46c5b477ff42 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 21 Feb 2017 09:05:22 -0500 Subject: [PATCH] Sort history completion entries by atime. --- qutebrowser/completion/models/sqlmodel.py | 7 +++---- qutebrowser/completion/models/urlmodel.py | 2 +- tests/unit/completion/test_sqlmodel.py | 14 +++++++------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/qutebrowser/completion/models/sqlmodel.py b/qutebrowser/completion/models/sqlmodel.py index 1053fb2f2..99c47cf28 100644 --- a/qutebrowser/completion/models/sqlmodel.py +++ b/qutebrowser/completion/models/sqlmodel.py @@ -49,9 +49,8 @@ class _SqlCompletionCategory(QSqlQueryModel): querystr += ' and ' + where if sort_by: - assert sort_order is not None - sortstr = 'asc' if sort_order == Qt.AscendingOrder else 'desc' - querystr += ' order by {} {}'.format(sort_by, sortstr) + assert sort_order == 'asc' or sort_order == 'desc' + querystr += ' order by {} {}'.format(sort_by, sort_order) if limit: querystr += ' limit {}'.format(limit) @@ -115,7 +114,7 @@ class SqlCompletionModel(QAbstractItemModel): select: A custom result column expression for the select statement. where: An optional clause to filter out some rows. sort_by: The name of the field to sort by, or None for no sorting. - sort_order: Sorting order, if sort_by is non-None. + sort_order: Either 'asc' or 'desc', if sort_by is non-None limit: Maximum row count to return on a query. Return: A new CompletionCategory. diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 387603dd5..6a10d9c44 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -70,7 +70,7 @@ def url(): model.new_category('Quickmarks', select='url, name') model.new_category('Bookmarks') model.new_category('History', - limit=limit, + limit=limit, sort_order='desc', sort_by='atime', select='url, title, {}'.format(select_time), where='not redirect') return model diff --git a/tests/unit/completion/test_sqlmodel.py b/tests/unit/completion/test_sqlmodel.py index 044eecb35..ab14bce75 100644 --- a/tests/unit/completion/test_sqlmodel.py +++ b/tests/unit/completion/test_sqlmodel.py @@ -73,31 +73,31 @@ def test_count(rowcounts, expected): @pytest.mark.parametrize('sort_by, sort_order, data, expected', [ - (None, Qt.AscendingOrder, + (None, 'asc', [('B', 'C', 'D'), ('A', 'F', 'C'), ('C', 'A', 'G')], [('B', 'C', 'D'), ('A', 'F', 'C'), ('C', 'A', 'G')]), - ('a', Qt.AscendingOrder, + ('a', 'asc', [('B', 'C', 'D'), ('A', 'F', 'C'), ('C', 'A', 'G')], [('A', 'F', 'C'), ('B', 'C', 'D'), ('C', 'A', 'G')]), - ('a', Qt.DescendingOrder, + ('a', 'desc', [('B', 'C', 'D'), ('A', 'F', 'C'), ('C', 'A', 'G')], [('C', 'A', 'G'), ('B', 'C', 'D'), ('A', 'F', 'C')]), - ('b', Qt.AscendingOrder, + ('b', 'asc', [('B', 'C', 'D'), ('A', 'F', 'C'), ('C', 'A', 'G')], [('C', 'A', 'G'), ('B', 'C', 'D'), ('A', 'F', 'C')]), - ('b', Qt.DescendingOrder, + ('b', 'desc', [('B', 'C', 'D'), ('A', 'F', 'C'), ('C', 'A', 'G')], [('A', 'F', 'C'), ('B', 'C', 'D'), ('C', 'A', 'G')]), - ('c', Qt.AscendingOrder, + ('c', 'asc', [('B', 'C', 2), ('A', 'F', 0), ('C', 'A', 1)], [('A', 'F', 0), ('C', 'A', 1), ('B', 'C', 2)]), - ('c', Qt.DescendingOrder, + ('c', 'desc', [('B', 'C', 2), ('A', 'F', 0), ('C', 'A', 1)], [('B', 'C', 2), ('C', 'A', 1), ('A', 'F', 0)]), ])