diff --git a/anki/deck.py b/anki/deck.py index b5dfbafd6..aa5490715 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -6,7 +6,7 @@ import time, os, random, re, stat, simplejson from anki.lang import _, ngettext from anki.utils import parseTags, tidyHTML, ids2str, hexifyID, \ - checksum, fieldChecksum, addTags, deleteTags, stripHTML, intTime, \ + checksum, fieldChecksum, addTags, delTags, stripHTML, intTime, \ splitFields from anki.hooks import runHook, runFilter from anki.sched import Scheduler @@ -208,7 +208,7 @@ qconf=?, conf=?, data=?""", ncards += 1 return ncards - def _deleteFacts(self, ids): + def _delFacts(self, ids): "Bulk delete facts by ID. Don't call this directly." if not ids: return @@ -216,11 +216,11 @@ qconf=?, conf=?, data=?""", self.db.execute("delete from facts where id in %s" % strids) self.db.execute("delete from fsums where fid in %s" % strids) - def _deleteDanglingFacts(self): + def _delDanglingFacts(self): "Delete any facts without cards. Don't call this directly." ids = self.db.list(""" select id from facts where id not in (select distinct fid from cards)""") - self._deleteFacts(ids) + self._delFacts(ids) return ids # Card creation @@ -304,11 +304,11 @@ select id from facts where id not in (select distinct fid from cards)""") def cardCount(self): return self.db.scalar("select count() from cards where crt != 0") - def deleteCard(self, id): + def delCard(self, id): "Delete a card given its id. Delete any unused facts." - self.deleteCards([id]) + self.delCards([id]) - def deleteCards(self, ids): + def delCards(self, ids): "Bulk delete cards by ID." if not ids: return @@ -319,7 +319,7 @@ select id from facts where id not in (select distinct fid from cards)""") self.db.execute("delete from cards where id in %s" % sids) self.db.execute("delete from revlog where cid in %s" % sids) # remove any dangling facts - self._deleteDanglingFacts() + self._delDanglingFacts() else: # trash sfids = ids2str( @@ -426,12 +426,12 @@ where id = :id""", vals) model.flush() self.conf['currentModelId'] = model.id - def deleteModel(self, mid): + def delModel(self, mid): "Delete MODEL, and all its cards/facts." # do a direct delete self.modSchema() # delete facts/cards - self.deleteCards(self.db.list(""" + self.delCards(self.db.list(""" select id from cards where fid in (select id from facts where mid = ?)""", mid)) # then the model @@ -569,7 +569,7 @@ insert or ignore into tags (mod, name) values (%d, :t)""" % intTime(), fn = addTags else: l = "tags " - fn = deleteTags + fn = delTags lim = " or ".join( [l+"like :_%d" % c for c, t in enumerate(newTags)]) res = self.db.all( @@ -586,7 +586,7 @@ update facts set tags = :t, mod = :n where id = :id""", [fix(row) for row in res self.registerTags(parseTags(tags)) self.finishProgress() - def deleteTags(self, ids, tags): + def delTags(self, ids, tags): self.addTags(ids, tags, False) # Finding cards diff --git a/anki/facts.py b/anki/facts.py index 757b44355..b363ee9ef 100644 --- a/anki/facts.py +++ b/anki/facts.py @@ -5,7 +5,7 @@ import time from anki.errors import AnkiError from anki.utils import stripHTMLMedia, fieldChecksum, intTime, \ - addTags, deleteTags, joinFields, splitFields, ids2str, parseTags + addTags, delTags, joinFields, splitFields, ids2str, parseTags class Fact(object): @@ -103,8 +103,8 @@ insert or replace into facts values (?, ?, ?, ?, ?, ?, ?, ?)""", def addTags(self, tags): self.tags = addTags(tags, self.tags) - def deleteTags(self, tags): - self.tags = deleteTags(tags, self.tags) + def delTags(self, tags): + self.tags = delTags(tags, self.tags) # Unique/duplicate checks ################################################## diff --git a/anki/models.py b/anki/models.py index 96530b581..2f47a6501 100644 --- a/anki/models.py +++ b/anki/models.py @@ -242,7 +242,7 @@ insert or replace into models values (?, ?, ?, ?, ?, ?, ?)""", cids = self.deck.db.list(""" select c.id from cards c, facts f where c.fid=f.id and mid = ? and ord = ?""", self.id, ord) - self.deck.deleteCards(cids) + self.deck.delCards(cids) # shift ordinals self.deck.db.execute(""" update cards set ord = ord - 1 where fid in (select id from facts diff --git a/anki/utils.py b/anki/utils.py index 732b6fb64..5f7ed5efe 100644 --- a/anki/utils.py +++ b/anki/utils.py @@ -242,7 +242,7 @@ def addTags(addtags, tags): currentTags.append(tag) return joinTags(currentTags) -def deleteTags(deltags, tags): +def delTags(deltags, tags): "Delete tags if they don't exists." currentTags = parseTags(tags) for tag in parseTags(deltags): diff --git a/tests/test_cards.py b/tests/test_cards.py index af7d7d5ea..60d010f93 100644 --- a/tests/test_cards.py +++ b/tests/test_cards.py @@ -57,7 +57,7 @@ def test_delete(): deck.reset() deck.sched.answerCard(deck.sched.getCard(), 2) assert deck.db.scalar("select count() from revlog") == 1 - deck.deleteCard(cid) + deck.delCard(cid) assert deck.cardCount() == 0 assert deck.factCount() == 0 assert deck.db.scalar("select count() from facts") == 0 @@ -71,7 +71,7 @@ def test_delete(): deck.lastSync = deck.schema + 1 # cards/facts should go in the deletion log instead cid = f.cards()[0].id - deck.deleteCard(cid) + deck.delCard(cid) assert deck.cardCount() == 0 assert deck.factCount() == 0 assert deck.db.scalar("select count() from facts") == 1 diff --git a/tests/test_deck.py b/tests/test_deck.py index 4520f4199..0cacd6709 100644 --- a/tests/test_deck.py +++ b/tests/test_deck.py @@ -74,11 +74,11 @@ def test_factAddDelete(): id1 = cards[0].id; id2 = cards[1].id assert deck.cardCount() == 2 assert deck.factCount() == 1 - deck.deleteCard(id1) + deck.delCard(id1) assert deck.cardCount() == 1 assert deck.factCount() == 1 # and the second should clear the fact - deck.deleteCard(id2) + deck.delCard(id2) assert deck.cardCount() == 0 assert deck.factCount() == 0 diff --git a/tests/test_find.py b/tests/test_find.py index 92f55a89a..6239de11b 100644 --- a/tests/test_find.py +++ b/tests/test_find.py @@ -35,6 +35,6 @@ def test_findCards(): assert (len(deck.findCards("tag:foo")) == len(deck.findCards("tag:bar")) == 3) - deck.deleteTags(deck.db.list("select id from cards"), "foo") + deck.delTags(deck.db.list("select id from cards"), "foo") assert len(deck.findCards("tag:foo")) == 0 assert len(deck.findCards("tag:bar")) == 3 diff --git a/tests/test_models.py b/tests/test_models.py index d40b4bcea..22fc607d1 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -11,7 +11,7 @@ def test_modelDelete(): f['Back'] = u'2' deck.addFact(f) assert deck.cardCount() == 1 - deck.deleteModel(deck.conf['currentModelId']) + deck.delModel(deck.conf['currentModelId']) assert deck.cardCount() == 0 def test_modelCopy():