本文整理汇总了Python中anki.decks.DeckManager.isDyn方法的典型用法代码示例。如果您正苦于以下问题:Python DeckManager.isDyn方法的具体用法?Python DeckManager.isDyn怎么用?Python DeckManager.isDyn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anki.decks.DeckManager
的用法示例。
在下文中一共展示了DeckManager.isDyn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _Collection
# 需要导入模块: from anki.decks import DeckManager [as 别名]
# 或者: from anki.decks.DeckManager import isDyn [as 别名]
#.........这里部分代码省略.........
dids = {}
for id, nid, ord, did in self.db.execute(
"select id, nid, ord, did from cards where nid in "+snids):
# existing cards
if nid not in have:
have[nid] = {}
have[nid][ord] = id
# and their dids
if nid in dids:
if dids[nid] and dids[nid] != did:
# cards are in two or more different decks; revert to
# model default
dids[nid] = None
else:
# first card or multiple cards in same deck
dids[nid] = did
# build cards for each note
data = []
ts = maxID(self.db)
now = intTime()
rem = []
usn = self.usn()
for nid, mid, flds in self.db.execute(
"select id, mid, flds from notes where id in "+snids):
model = self.models.get(mid)
avail = self.models.availOrds(model, flds)
did = dids.get(nid) or model['did']
# add any missing cards
for t in self._tmplsFromOrds(model, avail):
doHave = nid in have and t['ord'] in have[nid]
if not doHave:
# check deck is not a cram deck
did = t['did'] or did
if self.decks.isDyn(did):
did = 1
# if the deck doesn't exist, use default instead
did = self.decks.get(did)['id']
# we'd like to use the same due# as sibling cards, but we
# can't retrieve that quickly, so we give it a new id
# instead
data.append((ts, nid, did, t['ord'],
now, usn, self.nextID("pos")))
ts += 1
# note any cards that need removing
if nid in have:
for ord, id in have[nid].items():
if ord not in avail:
rem.append(id)
# bulk update
self.db.executemany("""
insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""",
data)
return rem
# type 0 - when previewing in add dialog, only non-empty
# type 1 - when previewing edit, only existing
# type 2 - when previewing in models dialog, all templates
def previewCards(self, note, type=0):
if type == 0:
cms = self.findTemplates(note)
elif type == 1:
cms = [c.template() for c in note.cards()]
else:
cms = note.model()['tmpls']
if not cms:
return []
示例2: _Collection
# 需要导入模块: from anki.decks import DeckManager [as 别名]
# 或者: from anki.decks.DeckManager import isDyn [as 别名]
#.........这里部分代码省略.........
dids = {}
for id, nid, ord, did in self.db.execute(
"select id, nid, ord, did from cards where nid in "+snids):
# existing cards
if nid not in have:
have[nid] = {}
have[nid][ord] = id
# and their dids
if nid in dids:
if dids[nid] and dids[nid] != did:
# cards are in two or more different decks; revert to
# model default
dids[nid] = None
else:
# first card or multiple cards in same deck
dids[nid] = did
# build cards for each note
data = []
ts = maxID(self.db)
now = intTime()
rem = []
usn = self.usn()
for nid, mid, flds in self.db.execute(
"select id, mid, flds from notes where id in "+snids):
model = self.models.get(mid)
avail = self.models.availOrds(model, flds)
did = dids.get(nid) or model['did']
# add any missing cards
for t in self._tmplsFromOrds(model, avail):
doHave = nid in have and t['ord'] in have[nid]
if not doHave:
# check deck is not a cram deck
did = t['did'] or did
if self.decks.isDyn(did):
did = 1
# if the deck doesn't exist, use default instead
did = self.decks.get(did)['id']
# we'd like to use the same due# as sibling cards, but we
# can't retrieve that quickly, so we give it a new id
# instead
data.append((ts, nid, did, t['ord'],
now, usn, self.nextID("pos")))
ts += 1
# note any cards that need removing
if nid in have:
for ord, id in have[nid].items():
if ord not in avail:
rem.append(id)
# bulk update
self.db.executemany("""
insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""",
data)
return rem
# type 0 - when previewing in add dialog, only non-empty
# type 1 - when previewing edit, only existing
# type 2 - when previewing in models dialog, all templates
def previewCards(self, note, type=0):
if type == 0:
cms = self.findTemplates(note)
elif type == 1:
cms = [c.template() for c in note.cards()]
else:
cms = note.model()['tmpls']
if not cms:
return []