mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
expose read-only access to new notetype objects
This commit is contained in:
parent
c60b88cd2f
commit
1a4c4373d2
4 changed files with 16 additions and 1 deletions
|
@ -43,7 +43,7 @@ from anki.decks import Deck, DeckId, DeckManager
|
||||||
from anki.errors import AbortSchemaModification, DBError
|
from anki.errors import AbortSchemaModification, DBError
|
||||||
from anki.lang import FormatTimeSpan
|
from anki.lang import FormatTimeSpan
|
||||||
from anki.media import MediaManager, media_paths_from_col_path
|
from anki.media import MediaManager, media_paths_from_col_path
|
||||||
from anki.models import ModelManager, NotetypeDict, NotetypeId
|
from anki.models import ModelManager, NotetypeDict, NotetypeId, Notetype
|
||||||
from anki.notes import Note, NoteId
|
from anki.notes import Note, NoteId
|
||||||
from anki.scheduler.v1 import Scheduler as V1Scheduler
|
from anki.scheduler.v1 import Scheduler as V1Scheduler
|
||||||
from anki.scheduler.v2 import Scheduler as V2Scheduler
|
from anki.scheduler.v2 import Scheduler as V2Scheduler
|
||||||
|
@ -335,6 +335,10 @@ class Collection:
|
||||||
"Get a new-style deck object. Currently read-only."
|
"Get a new-style deck object. Currently read-only."
|
||||||
return self._backend.get_deck(id)
|
return self._backend.get_deck(id)
|
||||||
|
|
||||||
|
def get_notetype(self, id: NotetypeId) -> Notetype:
|
||||||
|
"""Get a new-style notetype object. This is not cached; avoid calling frequently."""
|
||||||
|
return self._backend.get_notetype(id)
|
||||||
|
|
||||||
getCard = get_card
|
getCard = get_card
|
||||||
getNote = get_note
|
getNote = get_note
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ from anki.utils import (
|
||||||
)
|
)
|
||||||
|
|
||||||
# public exports
|
# public exports
|
||||||
|
Notetype = _pb.Notetype
|
||||||
NotetypeNameId = _pb.NotetypeNameId
|
NotetypeNameId = _pb.NotetypeNameId
|
||||||
NotetypeNameIdUseCount = _pb.NotetypeNameIdUseCount
|
NotetypeNameIdUseCount = _pb.NotetypeNameIdUseCount
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,7 @@ service ConfigService {
|
||||||
service NotetypesService {
|
service NotetypesService {
|
||||||
rpc AddOrUpdateNotetype(AddOrUpdateNotetypeIn) returns (NotetypeId);
|
rpc AddOrUpdateNotetype(AddOrUpdateNotetypeIn) returns (NotetypeId);
|
||||||
rpc GetStockNotetypeLegacy(StockNotetype) returns (Json);
|
rpc GetStockNotetypeLegacy(StockNotetype) returns (Json);
|
||||||
|
rpc GetNotetype(NotetypeId) returns (Notetype);
|
||||||
rpc GetNotetypeLegacy(NotetypeId) returns (Json);
|
rpc GetNotetypeLegacy(NotetypeId) returns (Json);
|
||||||
rpc GetNotetypeNames(Empty) returns (NotetypeNames);
|
rpc GetNotetypeNames(Empty) returns (NotetypeNames);
|
||||||
rpc GetNotetypeNamesAndCounts(Empty) returns (NotetypeUseCounts);
|
rpc GetNotetypeNamesAndCounts(Empty) returns (NotetypeUseCounts);
|
||||||
|
|
|
@ -34,6 +34,15 @@ impl NotetypesService for Backend {
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_notetype(&self, input: pb::NotetypeId) -> Result<pb::Notetype> {
|
||||||
|
self.with_col(|col| {
|
||||||
|
col.storage
|
||||||
|
.get_notetype(input.into())?
|
||||||
|
.ok_or(AnkiError::NotFound)
|
||||||
|
.map(Into::into)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn get_notetype_legacy(&self, input: pb::NotetypeId) -> Result<pb::Json> {
|
fn get_notetype_legacy(&self, input: pb::NotetypeId) -> Result<pb::Json> {
|
||||||
self.with_col(|col| {
|
self.with_col(|col| {
|
||||||
let schema11: NotetypeSchema11 = col
|
let schema11: NotetypeSchema11 = col
|
||||||
|
|
Loading…
Reference in a new issue