本文整理汇总了Python中anki.decks.DeckManager.confForDid方法的典型用法代码示例。如果您正苦于以下问题:Python DeckManager.confForDid方法的具体用法?Python DeckManager.confForDid怎么用?Python DeckManager.confForDid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anki.decks.DeckManager
的用法示例。
在下文中一共展示了DeckManager.confForDid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _Collection
# 需要导入模块: from anki.decks import DeckManager [as 别名]
# 或者: from anki.decks.DeckManager import confForDid [as 别名]
#.........这里部分代码省略.........
insert into cards values (?,?,?,?,?,?,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 []
cards = []
for template in cms:
cards.append(self._newCard(note, template, 1, flush=False))
return cards
def _newCard(self, note, template, due, flush=True):
"Create a new card."
card = anki.cards.Card(self)
card.nid = note.id
card.ord = template['ord']
card.did = template['did'] or note.did
card.due = self._dueForDid(card.did, due)
if flush:
card.flush()
return card
def _dueForDid(self, did, due):
conf = self.decks.confForDid(did)
# in order due?
if conf['new']['order']:
return due
else:
# random mode; seed with note ts so all cards of this note get the
# same random number
r = random.Random()
r.seed(due)
return r.randrange(1, 2**32-1)
# Cards
##########################################################################
def isEmpty(self):
return not self.db.scalar("select 1 from cards limit 1")
def cardCount(self):
return self.db.scalar("select count() from cards")
def remCards(self, ids):
"Bulk delete cards by ID."
if not ids:
return
sids = ids2str(ids)
nids = self.db.list("select nid from cards where id in "+sids)
# remove cards
self._logRem(ids, REM_CARD)
self.db.execute("delete from cards where id in "+sids)
self.db.execute("delete from revlog where cid in "+sids)
# then notes
nids = self.db.list("""
select id from notes where id in %s and id not in (select nid from cards)""" %
示例2: _Collection
# 需要导入模块: from anki.decks import DeckManager [as 别名]
# 或者: from anki.decks.DeckManager import confForDid [as 别名]
#.........这里部分代码省略.........
cms = [c.template() for c in note.cards()]
else:
cms = note.model()['tmpls']
if not cms:
return []
cards = []
for template in cms:
cards.append(self._newCard(note, template, 1, flush=False))
return cards
def _newCard(self, note, template, due, flush=True):
"Create a new card."
card = anki.cards.Card(self)
card.nid = note.id
card.ord = template['ord']
# Use template did (deck override) if valid, otherwise model did
if template['did'] and unicode(template['did']) in self.decks.decks:
card.did = template['did']
else:
card.did = note.model()['did']
# if invalid did, use default instead
deck = self.decks.get(card.did)
if deck['dyn']:
# must not be a filtered deck
card.did = 1
else:
card.did = deck['id']
card.due = self._dueForDid(card.did, due)
if flush:
card.flush()
return card
def _dueForDid(self, did, due):
conf = self.decks.confForDid(did)
# in order due?
if conf['new']['order'] == NEW_CARDS_DUE:
return due
else:
# random mode; seed with note ts so all cards of this note get the
# same random number
r = random.Random()
r.seed(due)
return r.randrange(1, max(due, 1000))
# Cards
##########################################################################
def isEmpty(self):
return not self.db.scalar("select 1 from cards limit 1")
def cardCount(self):
return self.db.scalar("select count() from cards")
def remCards(self, ids, notes=True):
"Bulk delete cards by ID."
if not ids:
return
sids = ids2str(ids)
nids = self.db.list("select nid from cards where id in "+sids)
# remove cards
self._logRem(ids, REM_CARD)
self.db.execute("delete from cards where id in "+sids)
# then notes
if not notes:
return
nids = self.db.list("""