mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
progress for importing
This commit is contained in:
parent
6015dbec04
commit
1fa7466dd9
2 changed files with 16 additions and 0 deletions
|
@ -46,8 +46,13 @@ class Importer(object):
|
|||
|
||||
def doImport(self):
|
||||
"Import."
|
||||
self.deck.startProgress(_("Import"), 0, 6)
|
||||
self.deck.updateProgress(_("Reading source..."))
|
||||
c = self.foreignCards()
|
||||
self.importCards(c)
|
||||
self.deck.updateProgress(_("Updating priorities..."))
|
||||
self.deck.updateAllPriorities()
|
||||
self.deck.finishProgress()
|
||||
if c:
|
||||
self.deck.setModified()
|
||||
|
||||
|
@ -118,6 +123,7 @@ all but one card template."""))
|
|||
def addCards(self, cards):
|
||||
"Add facts in bulk from foreign cards."
|
||||
# add facts
|
||||
self.deck.updateProgress(_("Adding facts..."))
|
||||
factIds = [genID() for n in range(len(cards))]
|
||||
self.deck.s.execute(factsTable.insert(),
|
||||
[{'modelId': self.model.id,
|
||||
|
@ -128,6 +134,7 @@ all but one card template."""))
|
|||
delete from factsDeleted
|
||||
where factId in (%s)""" % ",".join([str(s) for s in factIds]))
|
||||
# add all the fields
|
||||
self.deck.updateProgress(_("Adding fields..."))
|
||||
for fm in self.model.fieldModels:
|
||||
try:
|
||||
index = self.mapping.index(fm)
|
||||
|
@ -143,6 +150,7 @@ where factId in (%s)""" % ",".join([str(s) for s in factIds]))
|
|||
self.deck.s.execute(fieldsTable.insert(),
|
||||
data)
|
||||
# and cards
|
||||
self.deck.updateProgress(_("Adding cards..."))
|
||||
now = time.time()
|
||||
for cm in self.model.cardModels:
|
||||
self._now = now
|
||||
|
@ -157,6 +165,7 @@ where factId in (%s)""" % ",".join([str(s) for s in factIds]))
|
|||
'type': 2},cards[m]) for m in range(len(cards))]
|
||||
self.deck.s.execute(cardsTable.insert(),
|
||||
data)
|
||||
self.deck.updateProgress(_("Caching QA..."))
|
||||
self.deck.updateCardsFromModel(self.model)
|
||||
self.deck.cardCount += len(cards)
|
||||
self.total = len(factIds)
|
||||
|
@ -171,6 +180,7 @@ where factId in (%s)""" % ",".join([str(s) for s in factIds]))
|
|||
self._now += .00001
|
||||
data.update(card.__dict__)
|
||||
data['combinedDue'] = data['due']
|
||||
data['isDue'] = data['combinedDue'] < time.time()
|
||||
return data
|
||||
|
||||
def stripInvalid(self, cards):
|
||||
|
|
|
@ -18,6 +18,8 @@ class Anki10Importer(Importer):
|
|||
|
||||
def doImport(self):
|
||||
"Import."
|
||||
self.deck.startProgress(_("Import"), 0, 4)
|
||||
self.deck.updateProgress(_("Importing..."))
|
||||
src = DeckStorage.Deck(self.file)
|
||||
client = SyncClient(self.deck)
|
||||
server = SyncServer(src)
|
||||
|
@ -43,7 +45,9 @@ class Anki10Importer(Importer):
|
|||
assert payload['deleted-facts'] == []
|
||||
assert payload['deleted-cards'] == []
|
||||
assert payload['deleted-models'] == []
|
||||
self.deck.updateProgress()
|
||||
res = server.applyPayload(payload)
|
||||
self.deck.updateProgress()
|
||||
client.applyPayloadReply(res)
|
||||
if client.mediaSyncPending:
|
||||
bulkClient = BulkMediaSyncer(client.deck)
|
||||
|
@ -51,11 +55,13 @@ class Anki10Importer(Importer):
|
|||
bulkClient.server = bulkServer
|
||||
bulkClient.sync()
|
||||
# add tags
|
||||
self.deck.updateProgress()
|
||||
fids = [f[0] for f in res['added-facts']['facts']]
|
||||
self.deck.addTags(fids, self.tagsToAdd)
|
||||
self.total = len(res['added-facts']['facts'])
|
||||
src.s.rollback()
|
||||
self.deck.flushMod()
|
||||
self.deck.finishProgress()
|
||||
|
||||
def _clearDeleted(self, sum):
|
||||
sum['delcards'] = []
|
||||
|
|
Loading…
Reference in a new issue