delete -> del for consistency

This commit is contained in:
Damien Elmes 2011-03-13 19:08:19 +09:00
parent f74d9b68fe
commit e728d49232
8 changed files with 23 additions and 23 deletions

View file

@ -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

View file

@ -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
##################################################

View file

@ -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

View file

@ -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):

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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():