mirror of
https://github.com/ankitects/anki.git
synced 2025-11-09 14:17:13 -05:00
use deck of existing cards if all use same deck
This commit is contained in:
parent
c0b1fb9c5f
commit
609e165c95
2 changed files with 47 additions and 3 deletions
|
|
@ -277,11 +277,22 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
||||||
# build map of (nid,ord) so we don't create dupes
|
# build map of (nid,ord) so we don't create dupes
|
||||||
snids = ids2str(nids)
|
snids = ids2str(nids)
|
||||||
have = {}
|
have = {}
|
||||||
for id, nid, ord in self.db.execute(
|
dids = {}
|
||||||
"select id, nid, ord from cards where nid in "+snids):
|
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:
|
if nid not in have:
|
||||||
have[nid] = {}
|
have[nid] = {}
|
||||||
have[nid][ord] = id
|
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
|
# build cards for each note
|
||||||
data = []
|
data = []
|
||||||
ts = maxID(self.db)
|
ts = maxID(self.db)
|
||||||
|
|
@ -292,7 +303,7 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
|
||||||
"select id, mid, flds from notes where id in "+snids):
|
"select id, mid, flds from notes where id in "+snids):
|
||||||
model = self.models.get(mid)
|
model = self.models.get(mid)
|
||||||
avail = self.models.availOrds(model, flds)
|
avail = self.models.availOrds(model, flds)
|
||||||
did = model['did']
|
did = dids.get(nid) or model['did']
|
||||||
for t in model['tmpls']:
|
for t in model['tmpls']:
|
||||||
doHave = nid in have and t['ord'] in have[nid]
|
doHave = nid in have and t['ord'] in have[nid]
|
||||||
# if have ord but empty, add cid to remove list
|
# if have ord but empty, add cid to remove list
|
||||||
|
|
|
||||||
|
|
@ -92,3 +92,36 @@ def test_genrem():
|
||||||
# remHook("remEmptyCards", abort)
|
# remHook("remEmptyCards", abort)
|
||||||
# f.flush()
|
# f.flush()
|
||||||
# assert len(f.cards()) == 1
|
# assert len(f.cards()) == 1
|
||||||
|
|
||||||
|
def test_gendeck():
|
||||||
|
d = getEmptyDeck()
|
||||||
|
cloze = d.models.byName("Cloze")
|
||||||
|
d.models.setCurrent(cloze)
|
||||||
|
f = d.newNote()
|
||||||
|
f['Text'] = u'{{c1::one}}'
|
||||||
|
d.addNote(f)
|
||||||
|
assert d.cardCount() == 1
|
||||||
|
assert f.cards()[0].did == 1
|
||||||
|
# set the model to a new default deck
|
||||||
|
newId = d.decks.id("new")
|
||||||
|
cloze['did'] = newId
|
||||||
|
d.models.save(cloze)
|
||||||
|
# a newly generated card should share the first card's deck
|
||||||
|
f['Text'] += u'{{c2::two}}'
|
||||||
|
f.flush()
|
||||||
|
assert f.cards()[1].did == 1
|
||||||
|
# and same with multiple cards
|
||||||
|
f['Text'] += u'{{c3::three}}'
|
||||||
|
f.flush()
|
||||||
|
assert f.cards()[2].did == 1
|
||||||
|
# if one of the cards is in a different deck, it should revert to the
|
||||||
|
# model default
|
||||||
|
c = f.cards()[1]
|
||||||
|
c.did = newId
|
||||||
|
c.flush()
|
||||||
|
f['Text'] += u'{{c4::four}}'
|
||||||
|
f.flush()
|
||||||
|
assert f.cards()[3].did == newId
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue