embed BuiltinSortKind

This commit is contained in:
Damien Elmes 2021-01-31 17:08:22 +10:00
parent 5974163343
commit 260a270eb0
5 changed files with 27 additions and 33 deletions

View file

@ -42,7 +42,6 @@ assert rsbridge.buildhash() == anki.buildinfo.buildhash
# by external libraries (eg aqt) should be exported in the module that # by external libraries (eg aqt) should be exported in the module that
# refers to them, eg collection.py # refers to them, eg collection.py
SchedTimingToday = pb.SchedTimingTodayOut SchedTimingToday = pb.SchedTimingTodayOut
BuiltinSortKind = pb.BuiltinSearchOrder.BuiltinSortKind
BackendCard = pb.Card BackendCard = pb.Card
BackendNote = pb.Note BackendNote = pb.Note
Tag = pb.Tag Tag = pb.Tag

View file

@ -58,12 +58,14 @@ ConfigBoolKey = _pb.ConfigBool.Key # pylint: disable=no-member
EmptyCardsReport = _pb.EmptyCardsReport EmptyCardsReport = _pb.EmptyCardsReport
NoteWithEmptyCards = _pb.NoteWithEmptyCards NoteWithEmptyCards = _pb.NoteWithEmptyCards
GraphPreferences = _pb.GraphPreferences GraphPreferences = _pb.GraphPreferences
BuiltinSortKind = _pb.SortOrder.Builtin.Kind # pylint: disable=no-member
# pylint: disable=no-member # pylint: disable=no-member
if TYPE_CHECKING: if TYPE_CHECKING:
from anki.lang import FormatTimeSpanContextValue, TRValue from anki.lang import FormatTimeSpanContextValue, TRValue
ConfigBoolKeyValue = _pb.ConfigBool.KeyValue ConfigBoolKeyValue = _pb.ConfigBool.KeyValue
BuiltinSortKindValue = _pb.SortOrder.Builtin.KindValue
class Collection: class Collection:
@ -460,11 +462,7 @@ class Collection:
def find_cards( def find_cards(
self, self,
query: str, query: str,
order: Union[ order: Union[bool, str, BuiltinSortKindValue] = False,
bool,
str,
_pb.BuiltinSearchOrder.BuiltinSortKindValue, # pylint: disable=no-member
] = False,
reverse: bool = False, reverse: bool = False,
) -> Sequence[int]: ) -> Sequence[int]:
if isinstance(order, str): if isinstance(order, str):
@ -476,7 +474,7 @@ class Collection:
mode = _pb.SortOrder(none=_pb.Empty()) mode = _pb.SortOrder(none=_pb.Empty())
else: else:
mode = _pb.SortOrder( mode = _pb.SortOrder(
builtin=_pb.BuiltinSearchOrder(kind=order, reverse=reverse) builtin=_pb.SortOrder.Builtin(kind=order, reverse=reverse)
) )
return self.backend.search_cards(search=query, order=mode) return self.backend.search_cards(search=query, order=mode)

View file

@ -1,8 +1,7 @@
# coding: utf-8 # coding: utf-8
import pytest import pytest
from anki._backend import BuiltinSortKind from anki.collection import BuiltinSortKind, ConfigBoolKey
from anki.collection import ConfigBoolKey
from anki.consts import * from anki.consts import *
from tests.shared import getEmptyCol, isNearCutoff from tests.shared import getEmptyCol, isNearCutoff

View file

@ -729,11 +729,30 @@ message SearchCardsOut {
} }
message SortOrder { message SortOrder {
message Builtin {
enum Kind {
NOTE_CREATION = 0;
NOTE_MOD = 1;
NOTE_FIELD = 2;
NOTE_TAGS = 3;
NOTE_TYPE = 4;
CARD_MOD = 5;
CARD_REPS = 6;
CARD_DUE = 7;
CARD_EASE = 8;
CARD_LAPSES = 9;
CARD_INTERVAL = 10;
CARD_DECK = 11;
CARD_TEMPLATE = 12;
}
Kind kind = 1;
bool reverse = 2;
}
oneof value { oneof value {
Empty from_config = 1; Empty from_config = 1;
Empty none = 2; Empty none = 2;
string custom = 3; string custom = 3;
BuiltinSearchOrder builtin = 4; Builtin builtin = 4;
} }
} }
@ -745,26 +764,6 @@ message SearchNotesOut {
repeated int64 note_ids = 2; repeated int64 note_ids = 2;
} }
message BuiltinSearchOrder {
enum BuiltinSortKind {
NOTE_CREATION = 0;
NOTE_MOD = 1;
NOTE_FIELD = 2;
NOTE_TAGS = 3;
NOTE_TYPE = 4;
CARD_MOD = 5;
CARD_REPS = 6;
CARD_DUE = 7;
CARD_EASE = 8;
CARD_LAPSES = 9;
CARD_INTERVAL = 10;
CARD_DECK = 11;
CARD_TEMPLATE = 12;
}
BuiltinSortKind kind = 1;
bool reverse = 2;
}
message SearchTerm { message SearchTerm {
message Dupe { message Dupe {
int64 notetype_id = 1; int64 notetype_id = 1;

View file

@ -6,10 +6,9 @@ use crate::{
backend::dbproxy::db_command_bytes, backend::dbproxy::db_command_bytes,
backend_proto as pb, backend_proto as pb,
backend_proto::{ backend_proto::{
builtin_search_order::BuiltinSortKind as SortKindProto,
concatenate_searches_in::Separator as BoolSeparatorProto, concatenate_searches_in::Separator as BoolSeparatorProto,
sort_order::Value as SortOrderProto, AddOrUpdateDeckConfigLegacyIn, BackendResult, Empty, sort_order::builtin::Kind as SortKindProto, sort_order::Value as SortOrderProto,
RenderedTemplateReplacement, AddOrUpdateDeckConfigLegacyIn, BackendResult, Empty, RenderedTemplateReplacement,
}, },
card::{Card, CardID}, card::{Card, CardID},
card::{CardQueue, CardType}, card::{CardQueue, CardType},