mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 08:22:24 -04:00
remove availOrds() check in importer
Like adding individual cards, we now support importing material even if it wouldn't generate any cards, and the old availOrds check can't handle negated conditionals.
This commit is contained in:
parent
c601dcef24
commit
9f676dbe0b
1 changed files with 4 additions and 20 deletions
|
@ -2,7 +2,7 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
import html
|
import html
|
||||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
from typing import Dict, List, Optional, Tuple, Union
|
||||||
|
|
||||||
from anki.collection import _Collection
|
from anki.collection import _Collection
|
||||||
from anki.consts import NEW_CARDS_RANDOM, STARTING_FACTOR
|
from anki.consts import NEW_CARDS_RANDOM, STARTING_FACTOR
|
||||||
|
@ -136,7 +136,6 @@ class NoteImporter(Importer):
|
||||||
new = []
|
new = []
|
||||||
self._ids: List[int] = []
|
self._ids: List[int] = []
|
||||||
self._cards: List[Tuple] = []
|
self._cards: List[Tuple] = []
|
||||||
self._emptyNotes = False
|
|
||||||
dupeCount = 0
|
dupeCount = 0
|
||||||
dupes: List[str] = []
|
dupes: List[str] = []
|
||||||
for n in notes:
|
for n in notes:
|
||||||
|
@ -222,23 +221,13 @@ class NoteImporter(Importer):
|
||||||
)
|
)
|
||||||
self.log.append("%s, %s, %s." % (part1, part2, part3))
|
self.log.append("%s, %s, %s." % (part1, part2, part3))
|
||||||
self.log.extend(updateLog)
|
self.log.extend(updateLog)
|
||||||
if self._emptyNotes:
|
|
||||||
self.log.append(
|
|
||||||
_(
|
|
||||||
"""\
|
|
||||||
One or more notes were not imported, because they didn't generate any cards. \
|
|
||||||
This can happen when you have empty fields or when you have not mapped the \
|
|
||||||
content in the text file to the correct fields."""
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.total = len(self._ids)
|
self.total = len(self._ids)
|
||||||
|
|
||||||
def newData(self, n: ForeignNote) -> Optional[list]:
|
def newData(self, n: ForeignNote) -> Optional[list]:
|
||||||
id = self._nextID
|
id = self._nextID
|
||||||
self._nextID += 1
|
self._nextID += 1
|
||||||
self._ids.append(id)
|
self._ids.append(id)
|
||||||
if not self.processFields(n):
|
self.processFields(n)
|
||||||
return None
|
|
||||||
# note id for card updates later
|
# note id for card updates later
|
||||||
for ord, c in list(n.cards.items()):
|
for ord, c in list(n.cards.items()):
|
||||||
self._cards.append((id, ord, c))
|
self._cards.append((id, ord, c))
|
||||||
|
@ -263,8 +252,7 @@ content in the text file to the correct fields."""
|
||||||
|
|
||||||
def updateData(self, n: ForeignNote, id: int, sflds: List[str]) -> Optional[list]:
|
def updateData(self, n: ForeignNote, id: int, sflds: List[str]) -> Optional[list]:
|
||||||
self._ids.append(id)
|
self._ids.append(id)
|
||||||
if not self.processFields(n, sflds):
|
self.processFields(n, sflds)
|
||||||
return None
|
|
||||||
if self._tagsMapped:
|
if self._tagsMapped:
|
||||||
tags = self.col.tags.join(n.tags)
|
tags = self.col.tags.join(n.tags)
|
||||||
return [intTime(), self.col.usn(), n.fieldsStr, tags, id, n.fieldsStr, tags]
|
return [intTime(), self.col.usn(), n.fieldsStr, tags, id, n.fieldsStr, tags]
|
||||||
|
@ -304,7 +292,7 @@ where id = ? and flds != ?""",
|
||||||
|
|
||||||
def processFields(
|
def processFields(
|
||||||
self, note: ForeignNote, fields: Optional[List[str]] = None
|
self, note: ForeignNote, fields: Optional[List[str]] = None
|
||||||
) -> Any:
|
) -> None:
|
||||||
if not fields:
|
if not fields:
|
||||||
fields = [""] * len(self.model["flds"])
|
fields = [""] * len(self.model["flds"])
|
||||||
for c, f in enumerate(self.mapping):
|
for c, f in enumerate(self.mapping):
|
||||||
|
@ -316,10 +304,6 @@ where id = ? and flds != ?""",
|
||||||
sidx = self._fmap[f][0]
|
sidx = self._fmap[f][0]
|
||||||
fields[sidx] = note.fields[c]
|
fields[sidx] = note.fields[c]
|
||||||
note.fieldsStr = joinFields(fields)
|
note.fieldsStr = joinFields(fields)
|
||||||
ords = self.col.models.availOrds(self.model, note.fieldsStr)
|
|
||||||
if not ords:
|
|
||||||
self._emptyNotes = True
|
|
||||||
return ords
|
|
||||||
|
|
||||||
def updateCards(self) -> None:
|
def updateCards(self) -> None:
|
||||||
data = []
|
data = []
|
||||||
|
|
Loading…
Reference in a new issue