-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.py
32 lines (23 loc) · 749 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from aqt import mw
from .consts import *
def getTemplate(model, cardName):
for tmpl in model["tmpls"]:
if tmpl['name'] == cardName:
return tmpl
print(f"""No card type "{cardName}" in {model['name']}""")
return None
def getTemplateOrd(model, cardName):
tmpl = getTemplate(model, cardName)
if tmpl is None:
return None
return tmpl['ord']
def getCardId(note, cardName):
ord = getTemplateOrd(note.note_type(), cardName)
if ord is None:
return None
return mw.col.db.scalar("select id from cards where nid = ? and ord = ?", note.id, ord)
def getCard(note, cardName):
cid = getCardId(note, cardName)
if cid is None:
return None
return mw.col.getCard(cid)