mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
add a hook to customize imported deck name
This commit is contained in:
parent
de541617cf
commit
5c3f036936
1 changed files with 14 additions and 1 deletions
|
@ -8,6 +8,7 @@ from anki.utils import intTime, splitFields, joinFields, checksum
|
||||||
from anki.importing.base import Importer
|
from anki.importing.base import Importer
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from anki.lang import ngettext
|
from anki.lang import ngettext
|
||||||
|
from anki.hooks import runFilter
|
||||||
|
|
||||||
#
|
#
|
||||||
# Import a .anki2 file into the current collection. Used for migration from
|
# Import a .anki2 file into the current collection. Used for migration from
|
||||||
|
@ -42,6 +43,7 @@ class Anki2Importer(Importer):
|
||||||
|
|
||||||
def _import(self):
|
def _import(self):
|
||||||
self._decks = {}
|
self._decks = {}
|
||||||
|
self._prepareDeckPrefix()
|
||||||
if self.deckPrefix:
|
if self.deckPrefix:
|
||||||
id = self.dst.decks.id(self.deckPrefix)
|
id = self.dst.decks.id(self.deckPrefix)
|
||||||
self.dst.decks.select(id)
|
self.dst.decks.select(id)
|
||||||
|
@ -54,6 +56,17 @@ class Anki2Importer(Importer):
|
||||||
self.dst.db.execute("vacuum")
|
self.dst.db.execute("vacuum")
|
||||||
self.dst.db.execute("analyze")
|
self.dst.db.execute("analyze")
|
||||||
|
|
||||||
|
def _prepareDeckPrefix(self):
|
||||||
|
prefix = None
|
||||||
|
for deck in self.src.decks.all():
|
||||||
|
head = deck['name'].split("::")[0]
|
||||||
|
if not prefix:
|
||||||
|
prefix = head
|
||||||
|
else:
|
||||||
|
if prefix != head:
|
||||||
|
return
|
||||||
|
self.deckPrefix = runFilter("prepareImportPrefix", prefix)
|
||||||
|
|
||||||
# Notes
|
# Notes
|
||||||
######################################################################
|
######################################################################
|
||||||
# - should note new for wizard
|
# - should note new for wizard
|
||||||
|
@ -186,7 +199,7 @@ class Anki2Importer(Importer):
|
||||||
tmpname = "::".join(name.split("::")[1:])
|
tmpname = "::".join(name.split("::")[1:])
|
||||||
name = self.deckPrefix
|
name = self.deckPrefix
|
||||||
if tmpname:
|
if tmpname:
|
||||||
name += "::" + name
|
name += "::" + tmpname
|
||||||
# create in local
|
# create in local
|
||||||
newid = self.dst.decks.id(name)
|
newid = self.dst.decks.id(name)
|
||||||
# pull conf over
|
# pull conf over
|
||||||
|
|
Loading…
Reference in a new issue