mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
always generate new cards on edit; don't delete
This commit is contained in:
parent
88da227ce1
commit
8f1404642a
2 changed files with 6 additions and 22 deletions
|
@ -45,8 +45,7 @@ from notes where id = ?""", self.id)
|
|||
self._fmap = self.col.models.fieldMap(self._model)
|
||||
|
||||
def flush(self, mod=None):
|
||||
if self.model()['cloze']:
|
||||
self._clozePreFlush()
|
||||
self._preFlush()
|
||||
self.mod = mod if mod else intTime()
|
||||
self.usn = self.col.usn()
|
||||
sfld = stripHTML(self.fields[self.col.models.sortIdx(self._model)])
|
||||
|
@ -60,8 +59,7 @@ insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?,?)""",
|
|||
self.data)
|
||||
self.id = res.lastrowid
|
||||
self.col.tags.register(self.tags)
|
||||
if self.model()['cloze']:
|
||||
self._clozePostFlush()
|
||||
self._postFlush()
|
||||
|
||||
def joinedFields(self):
|
||||
return joinFields(self.fields)
|
||||
|
@ -148,21 +146,12 @@ insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?,?)""",
|
|||
# Flushing cloze notes
|
||||
##################################################
|
||||
|
||||
def _clozePreFlush(self):
|
||||
def _preFlush(self):
|
||||
# have we been added yet?
|
||||
self.newlyAdded = not self.col.db.scalar(
|
||||
"select 1 from cards where nid = ?", self.id)
|
||||
tmpls = self.col.findTemplates(self)
|
||||
ok = []
|
||||
for t in tmpls:
|
||||
ok.append(t['ord'])
|
||||
# check if there are cards referencing a deleted cloze
|
||||
if self.col.db.scalar(
|
||||
"select 1 from cards where nid = ? and ord not in %s" %
|
||||
ids2str(ok), self.id):
|
||||
# there are; abort, as the UI should have handled this
|
||||
raise Exception("UI should have deleted cloze")
|
||||
|
||||
def _clozePostFlush(self):
|
||||
def _postFlush(self):
|
||||
# generate missing cards
|
||||
if not self.newlyAdded:
|
||||
self.col.genCards([self.id])
|
||||
|
|
|
@ -166,13 +166,8 @@ def test_cloze():
|
|||
assert d.addNote(f) == 0
|
||||
f['Text'] = "hello {{c1::foo}}"
|
||||
assert d.addNote(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
|
||||
cnt = d.cardCount()
|
||||
f['Text'] = "{{c2::hello}} {{c1::foo}}"
|
||||
f.flush()
|
||||
assert d.cardCount() == cnt + 1
|
||||
|
|
Loading…
Reference in a new issue