when exporting without scheduling, revert decks to default conf

This commit is contained in:
Damien Elmes 2012-08-25 16:09:49 +09:00
parent 087533fbc5
commit 8aaff17ccf
2 changed files with 26 additions and 1 deletions

View file

@ -179,7 +179,12 @@ class AnkiExporter(Exporter):
if dids and d['id'] not in dids:
continue
if not d['dyn'] and d['conf'] != 1:
dconfs[d['conf']] = True
if self.includeSched:
dconfs[d['conf']] = True
if not self.includeSched:
# scheduling not included, so reset deck settings to default
d = dict(d)
d['conf'] = 1
self.dst.decks.update(d)
# copy used deck confs
for dc in self.src.decks.allConf():

View file

@ -28,13 +28,33 @@ def setup1():
@nose.with_setup(setup1)
def test_export_anki():
# create a new deck with its own conf to test conf copying
did = deck.decks.id("test")
dobj = deck.decks.get(did)
confId = deck.decks.confId("newconf")
conf = deck.decks.getConf(confId)
conf['new']['perDay'] = 5
deck.decks.save(conf)
deck.decks.setConf(dobj, confId)
# export
e = AnkiExporter(deck)
newname = unicode(tempfile.mkstemp(prefix="ankitest", suffix=".anki2")[1])
os.unlink(newname)
e.exportInto(newname)
# exporting should not have changed conf for original deck
conf = deck.decks.confForDid(did)
assert conf['id'] != 1
# connect to new deck
d2 = aopen(newname)
assert d2.cardCount() == 2
# as scheduling was reset, should also revert decks to default conf
did = d2.decks.id("test", create=False)
assert did
conf2 = d2.decks.confForDid(did)
assert conf2['new']['perDay'] == 20
dobj = d2.decks.get(did)
# conf should be 1
assert dobj['conf'] == 1
# try again, limited to a deck
newname = unicode(tempfile.mkstemp(prefix="ankitest", suffix=".anki2")[1])
os.unlink(newname)