mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
add newly created clozes too
This commit is contained in:
parent
46dd863f3c
commit
bbe2973952
3 changed files with 18 additions and 10 deletions
|
@ -306,6 +306,7 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
|||
if t['ord'] in avail:
|
||||
data.append((ts, fid, t['gid'] or gid, t['ord'],
|
||||
ts, fid))
|
||||
ts += 1
|
||||
# bulk update
|
||||
self.db.executemany("""
|
||||
insert into cards values (?,?,?,?,?,-1,0,0,?,0,0,0,0,0,0,0,"")""",
|
||||
|
|
|
@ -46,7 +46,7 @@ from facts where id = ?""", self.id)
|
|||
|
||||
def flush(self, mod=None):
|
||||
if self.model()['cloze']:
|
||||
self._clozeFlush()
|
||||
self._clozePreFlush()
|
||||
self.mod = mod if mod else intTime()
|
||||
self.usn = self.deck.usn()
|
||||
sfld = stripHTML(self.fields[self.deck.models.sortIdx(self._model)])
|
||||
|
@ -59,6 +59,8 @@ insert or replace into facts values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
|||
self.id = res.lastrowid
|
||||
self.updateFieldChecksums()
|
||||
self.deck.tags.register(self.tags)
|
||||
if self.model()['cloze']:
|
||||
self._clozePostFlush()
|
||||
|
||||
def joinedFields(self):
|
||||
return joinFields(self.fields)
|
||||
|
@ -183,7 +185,9 @@ insert or replace into facts values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
|||
# Flushing cloze facts
|
||||
##################################################
|
||||
|
||||
def _clozeFlush(self):
|
||||
def _clozePreFlush(self):
|
||||
self.newlyAdded = not self.deck.db.scalar(
|
||||
"select 1 from cards where fid = ?", self.id)
|
||||
tmpls = self.deck.findTemplates(self)
|
||||
ok = []
|
||||
for t in tmpls:
|
||||
|
@ -194,10 +198,8 @@ insert or replace into facts values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
|||
ids2str(ok), self.id):
|
||||
# there are; abort, as the UI should have handled this
|
||||
raise Exception("UI should have deleted cloze")
|
||||
|
||||
def _clozePostFlush(self):
|
||||
# generate missing cards
|
||||
# for t in tmpls:
|
||||
# if not self.deck.db.scalar(
|
||||
# "select 1 from cards where fid = ? and ord = ?",
|
||||
# self.id, t['ord']):
|
||||
# add.append(t)
|
||||
# have = self.deck.db.scalar(
|
||||
if not self.newlyAdded:
|
||||
self.deck.genCards([self.id])
|
||||
|
|
|
@ -165,10 +165,15 @@ def test_cloze():
|
|||
f['Text'] = "hello {{c1::foo}}"
|
||||
assert d.addFact(f) == 1
|
||||
# deleting a cloze should fail; the ui should clean up invalid cards
|
||||
cnt = d.cardCount()
|
||||
f['Text'] = "hello"
|
||||
assertException(Exception, lambda: f.flush())
|
||||
|
||||
|
||||
f['Text'] = "hello {{c1::foo}}"
|
||||
f.flush()
|
||||
# if we add another cloze, a card should be generated
|
||||
f['Text'] = "{{c2::hello}} {{c1::foo}}"
|
||||
f.flush()
|
||||
assert d.cardCount() == cnt + 1
|
||||
|
||||
def test_modelChange():
|
||||
deck = getEmptyDeck()
|
||||
|
|
Loading…
Reference in a new issue