mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
Merge branch 'new'
This commit is contained in:
commit
3068e79b42
5 changed files with 21 additions and 4 deletions
|
@ -137,6 +137,9 @@ class GroupManager(object):
|
||||||
assert gid != 1
|
assert gid != 1
|
||||||
if not str(gid) in self.groups:
|
if not str(gid) in self.groups:
|
||||||
return
|
return
|
||||||
|
# delete children first
|
||||||
|
for name, id in self.children(gid):
|
||||||
|
self.rem(id, cardsToo)
|
||||||
# delete cards too?
|
# delete cards too?
|
||||||
if cardsToo:
|
if cardsToo:
|
||||||
self.deck.remCards(self.cids(gid))
|
self.deck.remCards(self.cids(gid))
|
||||||
|
@ -264,12 +267,18 @@ usn=?,mod=? where id in %s""" % ids2str(cids),
|
||||||
# current group
|
# current group
|
||||||
self.deck.conf['curGroup'] = gid
|
self.deck.conf['curGroup'] = gid
|
||||||
# and active groups (current + all children)
|
# and active groups (current + all children)
|
||||||
|
actv = self.children(gid)
|
||||||
|
actv.sort()
|
||||||
|
self.deck.conf['activeGroups'] = [gid] + [a[1] for a in actv]
|
||||||
|
|
||||||
|
def children(self, gid):
|
||||||
|
"All children of gid, as (name, id)."
|
||||||
|
name = self.get(gid)['name']
|
||||||
actv = []
|
actv = []
|
||||||
for g in self.all():
|
for g in self.all():
|
||||||
if g['name'].startswith(name + "::"):
|
if g['name'].startswith(name + "::"):
|
||||||
actv.append((g['name'], g['id']))
|
actv.append((g['name'], g['id']))
|
||||||
actv.sort()
|
return actv
|
||||||
self.deck.conf['activeGroups'] = [gid] + [a[1] for a in actv]
|
|
||||||
|
|
||||||
def parents(self, gid):
|
def parents(self, gid):
|
||||||
"All parents of gid."
|
"All parents of gid."
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Anki1Importer(Anki2Importer):
|
||||||
# merge
|
# merge
|
||||||
deck.close()
|
deck.close()
|
||||||
mdir = self.file.replace(".anki", ".media")
|
mdir = self.file.replace(".anki", ".media")
|
||||||
self.file = deck.path
|
|
||||||
self.groupPrefix = os.path.basename(self.file).replace(".anki", "")
|
self.groupPrefix = os.path.basename(self.file).replace(".anki", "")
|
||||||
|
self.file = deck.path
|
||||||
Anki2Importer.run(self, mdir)
|
Anki2Importer.run(self, mdir)
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ class Anki2Importer(Importer):
|
||||||
self._importFacts()
|
self._importFacts()
|
||||||
self._importCards()
|
self._importCards()
|
||||||
self._importMedia()
|
self._importMedia()
|
||||||
|
self.dst.db.execute("vacuum")
|
||||||
|
self.dst.db.execute("analyze")
|
||||||
|
|
||||||
# Facts
|
# Facts
|
||||||
######################################################################
|
######################################################################
|
||||||
|
@ -109,6 +111,8 @@ class Anki2Importer(Importer):
|
||||||
return dmid
|
return dmid
|
||||||
# need to add to local and update index
|
# need to add to local and update index
|
||||||
m = self.dst.models._add(self.src.models.get(mid))
|
m = self.dst.models._add(self.src.models.get(mid))
|
||||||
|
# need to save so the css is updated
|
||||||
|
self.dst.models.save(m)
|
||||||
h = self.dst.models.scmhash(m)
|
h = self.dst.models.scmhash(m)
|
||||||
mid = int(m['id'])
|
mid = int(m['id'])
|
||||||
self._dstModels[mid] = h
|
self._dstModels[mid] = h
|
||||||
|
|
|
@ -168,6 +168,8 @@ If the same name exists, compare checksums."""
|
||||||
|
|
||||||
def copyTo(self, rdir):
|
def copyTo(self, rdir):
|
||||||
ldir = self.dir()
|
ldir = self.dir()
|
||||||
|
if not os.path.exists(ldir):
|
||||||
|
return
|
||||||
for f in os.listdir(ldir):
|
for f in os.listdir(ldir):
|
||||||
src = os.path.join(ldir, f)
|
src = os.path.join(ldir, f)
|
||||||
dst = os.path.join(rdir, f)
|
dst = os.path.join(rdir, f)
|
||||||
|
|
|
@ -94,7 +94,9 @@ class ModelManager(object):
|
||||||
def current(self):
|
def current(self):
|
||||||
"Get current model."
|
"Get current model."
|
||||||
try:
|
try:
|
||||||
return self.get(self.deck.groups.top()['curModel'])
|
m = self.get(self.deck.groups.top()['curModel'])
|
||||||
|
assert m
|
||||||
|
return m
|
||||||
except:
|
except:
|
||||||
return self.models.values()[0]
|
return self.models.values()[0]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue