From 87febe489e56fe04a093eb439981ac0c4e12cd3c Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 12 Feb 2021 01:59:35 +0100 Subject: [PATCH] Allow for passing in custom note type and template --- pylib/anki/notes.py | 12 ++++++------ qt/aqt/clayout.py | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pylib/anki/notes.py b/pylib/anki/notes.py index 9121bf83e..19b8e5fb8 100644 --- a/pylib/anki/notes.py +++ b/pylib/anki/notes.py @@ -11,7 +11,7 @@ import anki # pylint: disable=unused-import import anki._backend.backend_pb2 as _pb from anki import hooks from anki.consts import MODEL_STD -from anki.models import NoteType +from anki.models import NoteType, Template from anki.utils import joinFields @@ -82,18 +82,18 @@ class Note: ord: int = 0, *, custom_note_type: NoteType = None, + custom_template: Template = None, fill_empty: bool = False, ) -> anki.cards.Card: card = anki.cards.Card(self.col) card.ord = ord card.did = 1 - model = self.model() + model = custom_note_type or self.model() template = copy.copy( - custom_note_type or ( - model["tmpls"][ord] - if model["type"] == MODEL_STD - else model["tmpls"][0] + custom_template + or ( + model["tmpls"][ord] if model["type"] == MODEL_STD else model["tmpls"][0] ) ) # may differ in cloze case diff --git a/qt/aqt/clayout.py b/qt/aqt/clayout.py index 0e8a5797b..3002d4add 100644 --- a/qt/aqt/clayout.py +++ b/qt/aqt/clayout.py @@ -476,7 +476,8 @@ class CardLayout(QDialog): c = self.rendered_card = self.note.ephemeral_card( self.ord, - custom_note_type=self.current_template(), + custom_note_type=self.model, + custom_template=self.current_template(), fill_empty=self.fill_empty_action_toggled, )