replace add missing active cards with selectable version

This commit is contained in:
Damien Elmes 2008-11-28 17:13:47 +09:00
parent 8147e5002a
commit 5119e46e7b

View file

@ -797,11 +797,11 @@ and due < :now""", now=time.time())
self.flushMod() self.flushMod()
return cards return cards
def availableCardModels(self, fact): def availableCardModels(self, fact, checkActive=True):
"List of active card models that aren't empty for FACT." "List of active card models that aren't empty for FACT."
models = [] models = []
for cardModel in fact.model.cardModels: for cardModel in fact.model.cardModels:
if cardModel.active: if cardModel.active or not checkActive:
ok = True ok = True
for format in [cardModel.qformat, cardModel.aformat]: for format in [cardModel.qformat, cardModel.aformat]:
empty = {} empty = {}
@ -821,16 +821,16 @@ and due < :now""", now=time.time())
models.append(cardModel) models.append(cardModel)
return models return models
def addMissingCards(self, fact): def addCards(self, fact, cardModelIds):
"Caller must flush first, flushMod after, and rebuild priorities." "Caller must flush first, flushMod after, and rebuild priorities."
for cardModel in fact.model.cardModels: for cardModel in self.availableCardModels(fact, False):
if cardModel.active: if cardModel.id not in cardModelIds:
if self.s.scalar(""" continue
if self.s.scalar("""
select count(id) from cards select count(id) from cards
where factId = :fid and cardModelId = :cmid""", where factId = :fid and cardModelId = :cmid""",
fid=fact.id, cmid=cardModel.id) == 0: fid=fact.id, cmid=cardModel.id) == 0:
card = anki.cards.Card(fact, cardModel) card = anki.cards.Card(fact, cardModel)
# not added to queue
self.setModified() self.setModified()
def factIsInvalid(self, fact): def factIsInvalid(self, fact):