From 407358ab686be83df03bd34008ff93cf797fb089 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Thu, 28 Jan 2021 16:21:56 +0100 Subject: [PATCH] Use backend nid filter in browser --- pylib/anki/collection.py | 4 ++++ pylib/anki/rsbackend.py | 1 + qt/aqt/browser.py | 6 +++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index b16bfcbef..4eec7758f 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -35,6 +35,7 @@ from anki.rsbackend import ( # pylint: disable=unused-import FormatTimeSpanContext, InvalidInput, NamedFilter, + NoteIDs, Progress, RustBackend, pb, @@ -503,6 +504,7 @@ class Collection: forgot_in: Optional[int] = None, added_in: Optional[int] = None, due_in: Optional[int] = None, + nids: Optional[List[int]] = None, ) -> str: filters = searches or [] @@ -528,6 +530,8 @@ class Collection: append_filter(FilterToSearchIn(added_in=added_in)) if due_in: append_filter(FilterToSearchIn(due_in=due_in)) + if nids: + append_filter(FilterToSearchIn(nids=NoteIDs(nids=nids))) if concat_by_or: sep = ConcatSeparator.OR else: diff --git a/pylib/anki/rsbackend.py b/pylib/anki/rsbackend.py index 0a4c20b03..d4b16fe71 100644 --- a/pylib/anki/rsbackend.py +++ b/pylib/anki/rsbackend.py @@ -50,6 +50,7 @@ StockNoteType = pb.StockNoteType FilterToSearchIn = pb.FilterToSearchIn NamedFilter = pb.FilterToSearchIn.NamedFilter DupeIn = pb.FilterToSearchIn.DupeIn +NoteIDs = pb.NoteIDs BackendNoteTypeID = pb.NoteTypeID ConcatSeparator = pb.ConcatenateSearchesIn.Separator SyncAuth = pb.SyncAuth diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 1cb65fc86..e1e474e38 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -659,7 +659,7 @@ class Browser(QMainWindow): c = self.card = self.mw.reviewer.card nid = c and c.nid or 0 if nid: - search = "nid:%d" % nid + search = self.col.search_string(nids=[nid]) search = gui_hooks.default_search(search, c) self.model.search(search) self.focusCid(c.id) @@ -1494,7 +1494,7 @@ where id in %s""" tv = self.form.tableView tv.selectionModel().clear() - search = "nid:" + ",".join([str(x) for x in nids]) + search = self.col.search_string(nids=nids) self.search_for(search) tv.selectAll() @@ -1705,7 +1705,7 @@ where id in %s""" t += ( """
  • %s: %s""" % ( - "nid:" + ",".join(str(id) for id in nids), + self.col.search_string(nids=nids).replace('"', '"'), tr(TR.BROWSING_NOTE_COUNT, count=len(nids)), html.escape(val), )