Allow for passing in custom note type and template

This commit is contained in:
Henrik Giesel 2021-02-12 01:59:35 +01:00
parent 270cef63f4
commit 87febe489e
2 changed files with 8 additions and 7 deletions

View File

@ -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

View File

@ -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,
)