Remove unnecessary anki.* qualification of already imported Note, Card

This commit is contained in:
Michal Pokorný (Rai) 2019-12-27 18:01:39 +01:00
parent 7abd58382f
commit 4a89cd1a25

View file

@ -12,12 +12,10 @@ import re
import stat import stat
import time import time
import traceback import traceback
from typing import Any, Dict, List, Optional, Tuple, Union from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
import anki.cards
import anki.find import anki.find
import anki.latex # sets up hook import anki.latex # sets up hook
import anki.notes
import anki.template import anki.template
from anki.backend import Backend from anki.backend import Backend
from anki.cards import Card from anki.cards import Card
@ -310,11 +308,11 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
# Object creation helpers # Object creation helpers
########################################################################## ##########################################################################
def getCard(self, id: int) -> anki.cards.Card: def getCard(self, id: int) -> Card:
return anki.cards.Card(self, id) return Card(self, id)
def getNote(self, id: int) -> anki.notes.Note: def getNote(self, id: int) -> Note:
return anki.notes.Note(self, id=id) return Note(self, id=id)
# Utils # Utils
########################################################################## ##########################################################################
@ -345,12 +343,12 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
def noteCount(self) -> Any: def noteCount(self) -> Any:
return self.db.scalar("select count() from notes") return self.db.scalar("select count() from notes")
def newNote(self, forDeck: bool = True) -> anki.notes.Note: def newNote(self, forDeck: bool = True) -> Note:
"Return a new note with the current model." "Return a new note with the current model."
return anki.notes.Note(self, self.models.current(forDeck)) return Note(self, self.models.current(forDeck))
def addNote(self, note: Note) -> int: def addNote(self, note: Note) -> int:
"Add a note to the collection. Return number of new cards." """Add a note to the collection. Return number of new cards."""
# check we have card models available, then save # check we have card models available, then save
cms = self.findTemplates(note) cms = self.findTemplates(note)
if not cms: if not cms:
@ -365,11 +363,12 @@ crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
ncards += 1 ncards += 1
return ncards return ncards
def remNotes(self, ids) -> None: def remNotes(self, ids: Iterable[int]) -> None:
"""Deletes notes with the given IDs."""
self.remCards(self.db.list("select id from cards where nid in " + ids2str(ids))) self.remCards(self.db.list("select id from cards where nid in " + ids2str(ids)))
def _remNotes(self, ids: List[int]) -> None: def _remNotes(self, ids: List[int]) -> None:
"Bulk delete notes by ID. Don't call this directly." """Bulk delete notes by ID. Don't call this directly."""
if not ids: if not ids:
return return
strids = ids2str(ids) strids = ids2str(ids)
@ -501,9 +500,9 @@ insert into cards values (?,?,?,?,?,?,0,0,?,0,0,0,0,0,0,0,0,"")""",
due: int, due: int,
flush: bool = True, flush: bool = True,
did: None = None, did: None = None,
) -> anki.cards.Card: ) -> Card:
"Create a new card." "Create a new card."
card = anki.cards.Card(self) card = Card(self)
card.nid = note.id card.nid = note.id
card.ord = template["ord"] card.ord = template["ord"]
card.did = self.db.scalar( card.did = self.db.scalar(
@ -571,6 +570,7 @@ select id from notes where id in %s and id not in (select nid from cards)"""
self._remNotes(nids) self._remNotes(nids)
def emptyCids(self) -> List[int]: def emptyCids(self) -> List[int]:
"""Returns IDs of empty cards."""
rem: List[int] = [] rem: List[int] = []
for m in self.models.all(): for m in self.models.all():
rem += self.genCards(self.models.nids(m)) rem += self.genCards(self.models.nids(m))