本文整理汇总了Python中anki.models.ModelManager.nids方法的典型用法代码示例。如果您正苦于以下问题:Python ModelManager.nids方法的具体用法?Python ModelManager.nids怎么用?Python ModelManager.nids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anki.models.ModelManager
的用法示例。
在下文中一共展示了ModelManager.nids方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _Collection
# 需要导入模块: from anki.models import ModelManager [as 别名]
# 或者: from anki.models.ModelManager import nids [as 别名]
#.........这里部分代码省略.........
for template in cms:
self._newCard(note, template, due)
ncards += 1
return ncards
def remNotes(self, ids):
self.remCards(self.db.list("select id from cards where nid in "+
ids2str(ids)))
def _remNotes(self, ids):
"Bulk delete notes by ID. Don't call this directly."
if not ids:
return
strids = ids2str(ids)
# we need to log these independently of cards, as one side may have
# more card templates
self._logRem(ids, REM_NOTE)
self.db.execute("delete from notes where id in %s" % strids)
# Card creation
##########################################################################
def findTemplates(self, note):
"Return (active), non-empty templates."
ok = []
model = note.model()
avail = self.models.availOrds(model, joinFields(note.fields))
ok = []
for t in model['tmpls']:
if t['ord'] in avail:
ok.append(t)
return ok
def genCards(self, nids):
"Generate cards for non-empty templates, return ids to remove."
# build map of (nid,ord) so we don't create dupes
snids = ids2str(nids)
have = {}
for id, nid, ord in self.db.execute(
"select id, nid, ord from cards where nid in "+snids):
if nid not in have:
have[nid] = {}
have[nid][ord] = id
# build cards for each note
data = []
ts = maxID(self.db)
now = intTime()
rem = []
usn = self.usn()
for nid, mid, did, flds in self.db.execute(
"select id, mid, did, flds from notes where id in "+snids):
model = self.models.get(mid)
avail = self.models.availOrds(model, flds)
ok = []
for t in model['tmpls']:
doHave = nid in have and t['ord'] in have[nid]
# if have ord but empty, add cid to remove list
# (may not have nid if generating before any cards added)
if doHave and t['ord'] not in avail:
rem.append(have[nid][t['ord']])
# if missing ord and is available, generate
if not doHave and t['ord'] in avail:
data.append((ts, nid, t['did'] or did, t['ord'],
now, usn, nid))
ts += 1
# bulk update
示例2: _Collection
# 需要导入模块: from anki.models import ModelManager [as 别名]
# 或者: from anki.models.ModelManager import nids [as 别名]
#.........这里部分代码省略.........
"Bulk delete notes by ID. Don't call this directly."
if not ids:
return
strids = ids2str(ids)
# we need to log these independently of cards, as one side may have
# more card templates
runHook("remNotes", self, ids)
self._logRem(ids, REM_NOTE)
self.db.execute("delete from notes where id in %s" % strids)
# Card creation
##########################################################################
def findTemplates(self, note):
"Return (active), non-empty templates."
model = note.model()
avail = self.models.availOrds(model, joinFields(note.fields))
return self._tmplsFromOrds(model, avail)
def _tmplsFromOrds(self, model, avail):
ok = []
if model['type'] == MODEL_STD:
for t in model['tmpls']:
if t['ord'] in avail:
ok.append(t)
else:
# cloze - generate temporary templates from first
for ord in avail:
t = copy.copy(model['tmpls'][0])
t['ord'] = ord
ok.append(t)
return ok
def genCards(self, nids):
"Generate cards for non-empty templates, return ids to remove."
# build map of (nid,ord) so we don't create dupes
snids = ids2str(nids)
have = {}
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