mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -04:00
delete -> del for consistency
This commit is contained in:
parent
f74d9b68fe
commit
e728d49232
8 changed files with 23 additions and 23 deletions
24
anki/deck.py
24
anki/deck.py
|
@ -6,7 +6,7 @@ import time, os, random, re, stat, simplejson
|
||||||
|
|
||||||
from anki.lang import _, ngettext
|
from anki.lang import _, ngettext
|
||||||
from anki.utils import parseTags, tidyHTML, ids2str, hexifyID, \
|
from anki.utils import parseTags, tidyHTML, ids2str, hexifyID, \
|
||||||
checksum, fieldChecksum, addTags, deleteTags, stripHTML, intTime, \
|
checksum, fieldChecksum, addTags, delTags, stripHTML, intTime, \
|
||||||
splitFields
|
splitFields
|
||||||
from anki.hooks import runHook, runFilter
|
from anki.hooks import runHook, runFilter
|
||||||
from anki.sched import Scheduler
|
from anki.sched import Scheduler
|
||||||
|
@ -208,7 +208,7 @@ qconf=?, conf=?, data=?""",
|
||||||
ncards += 1
|
ncards += 1
|
||||||
return ncards
|
return ncards
|
||||||
|
|
||||||
def _deleteFacts(self, ids):
|
def _delFacts(self, ids):
|
||||||
"Bulk delete facts by ID. Don't call this directly."
|
"Bulk delete facts by ID. Don't call this directly."
|
||||||
if not ids:
|
if not ids:
|
||||||
return
|
return
|
||||||
|
@ -216,11 +216,11 @@ qconf=?, conf=?, data=?""",
|
||||||
self.db.execute("delete from facts where id in %s" % strids)
|
self.db.execute("delete from facts where id in %s" % strids)
|
||||||
self.db.execute("delete from fsums where fid 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."
|
"Delete any facts without cards. Don't call this directly."
|
||||||
ids = self.db.list("""
|
ids = self.db.list("""
|
||||||
select id from facts where id not in (select distinct fid from cards)""")
|
select id from facts where id not in (select distinct fid from cards)""")
|
||||||
self._deleteFacts(ids)
|
self._delFacts(ids)
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
# Card creation
|
# Card creation
|
||||||
|
@ -304,11 +304,11 @@ select id from facts where id not in (select distinct fid from cards)""")
|
||||||
def cardCount(self):
|
def cardCount(self):
|
||||||
return self.db.scalar("select count() from cards where crt != 0")
|
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."
|
"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."
|
"Bulk delete cards by ID."
|
||||||
if not ids:
|
if not ids:
|
||||||
return
|
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 cards where id in %s" % sids)
|
||||||
self.db.execute("delete from revlog where cid in %s" % sids)
|
self.db.execute("delete from revlog where cid in %s" % sids)
|
||||||
# remove any dangling facts
|
# remove any dangling facts
|
||||||
self._deleteDanglingFacts()
|
self._delDanglingFacts()
|
||||||
else:
|
else:
|
||||||
# trash
|
# trash
|
||||||
sfids = ids2str(
|
sfids = ids2str(
|
||||||
|
@ -426,12 +426,12 @@ where id = :id""", vals)
|
||||||
model.flush()
|
model.flush()
|
||||||
self.conf['currentModelId'] = model.id
|
self.conf['currentModelId'] = model.id
|
||||||
|
|
||||||
def deleteModel(self, mid):
|
def delModel(self, mid):
|
||||||
"Delete MODEL, and all its cards/facts."
|
"Delete MODEL, and all its cards/facts."
|
||||||
# do a direct delete
|
# do a direct delete
|
||||||
self.modSchema()
|
self.modSchema()
|
||||||
# delete facts/cards
|
# 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 = ?)""",
|
select id from cards where fid in (select id from facts where mid = ?)""",
|
||||||
mid))
|
mid))
|
||||||
# then the model
|
# then the model
|
||||||
|
@ -569,7 +569,7 @@ insert or ignore into tags (mod, name) values (%d, :t)""" % intTime(),
|
||||||
fn = addTags
|
fn = addTags
|
||||||
else:
|
else:
|
||||||
l = "tags "
|
l = "tags "
|
||||||
fn = deleteTags
|
fn = delTags
|
||||||
lim = " or ".join(
|
lim = " or ".join(
|
||||||
[l+"like :_%d" % c for c, t in enumerate(newTags)])
|
[l+"like :_%d" % c for c, t in enumerate(newTags)])
|
||||||
res = self.db.all(
|
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.registerTags(parseTags(tags))
|
||||||
self.finishProgress()
|
self.finishProgress()
|
||||||
|
|
||||||
def deleteTags(self, ids, tags):
|
def delTags(self, ids, tags):
|
||||||
self.addTags(ids, tags, False)
|
self.addTags(ids, tags, False)
|
||||||
|
|
||||||
# Finding cards
|
# Finding cards
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
import time
|
import time
|
||||||
from anki.errors import AnkiError
|
from anki.errors import AnkiError
|
||||||
from anki.utils import stripHTMLMedia, fieldChecksum, intTime, \
|
from anki.utils import stripHTMLMedia, fieldChecksum, intTime, \
|
||||||
addTags, deleteTags, joinFields, splitFields, ids2str, parseTags
|
addTags, delTags, joinFields, splitFields, ids2str, parseTags
|
||||||
|
|
||||||
class Fact(object):
|
class Fact(object):
|
||||||
|
|
||||||
|
@ -103,8 +103,8 @@ insert or replace into facts values (?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||||
def addTags(self, tags):
|
def addTags(self, tags):
|
||||||
self.tags = addTags(tags, self.tags)
|
self.tags = addTags(tags, self.tags)
|
||||||
|
|
||||||
def deleteTags(self, tags):
|
def delTags(self, tags):
|
||||||
self.tags = deleteTags(tags, self.tags)
|
self.tags = delTags(tags, self.tags)
|
||||||
|
|
||||||
# Unique/duplicate checks
|
# Unique/duplicate checks
|
||||||
##################################################
|
##################################################
|
||||||
|
|
|
@ -242,7 +242,7 @@ insert or replace into models values (?, ?, ?, ?, ?, ?, ?)""",
|
||||||
cids = self.deck.db.list("""
|
cids = self.deck.db.list("""
|
||||||
select c.id from cards c, facts f where c.fid=f.id and mid = ? and ord = ?""",
|
select c.id from cards c, facts f where c.fid=f.id and mid = ? and ord = ?""",
|
||||||
self.id, ord)
|
self.id, ord)
|
||||||
self.deck.deleteCards(cids)
|
self.deck.delCards(cids)
|
||||||
# shift ordinals
|
# shift ordinals
|
||||||
self.deck.db.execute("""
|
self.deck.db.execute("""
|
||||||
update cards set ord = ord - 1 where fid in (select id from facts
|
update cards set ord = ord - 1 where fid in (select id from facts
|
||||||
|
|
|
@ -242,7 +242,7 @@ def addTags(addtags, tags):
|
||||||
currentTags.append(tag)
|
currentTags.append(tag)
|
||||||
return joinTags(currentTags)
|
return joinTags(currentTags)
|
||||||
|
|
||||||
def deleteTags(deltags, tags):
|
def delTags(deltags, tags):
|
||||||
"Delete tags if they don't exists."
|
"Delete tags if they don't exists."
|
||||||
currentTags = parseTags(tags)
|
currentTags = parseTags(tags)
|
||||||
for tag in parseTags(deltags):
|
for tag in parseTags(deltags):
|
||||||
|
|
|
@ -57,7 +57,7 @@ def test_delete():
|
||||||
deck.reset()
|
deck.reset()
|
||||||
deck.sched.answerCard(deck.sched.getCard(), 2)
|
deck.sched.answerCard(deck.sched.getCard(), 2)
|
||||||
assert deck.db.scalar("select count() from revlog") == 1
|
assert deck.db.scalar("select count() from revlog") == 1
|
||||||
deck.deleteCard(cid)
|
deck.delCard(cid)
|
||||||
assert deck.cardCount() == 0
|
assert deck.cardCount() == 0
|
||||||
assert deck.factCount() == 0
|
assert deck.factCount() == 0
|
||||||
assert deck.db.scalar("select count() from facts") == 0
|
assert deck.db.scalar("select count() from facts") == 0
|
||||||
|
@ -71,7 +71,7 @@ def test_delete():
|
||||||
deck.lastSync = deck.schema + 1
|
deck.lastSync = deck.schema + 1
|
||||||
# cards/facts should go in the deletion log instead
|
# cards/facts should go in the deletion log instead
|
||||||
cid = f.cards()[0].id
|
cid = f.cards()[0].id
|
||||||
deck.deleteCard(cid)
|
deck.delCard(cid)
|
||||||
assert deck.cardCount() == 0
|
assert deck.cardCount() == 0
|
||||||
assert deck.factCount() == 0
|
assert deck.factCount() == 0
|
||||||
assert deck.db.scalar("select count() from facts") == 1
|
assert deck.db.scalar("select count() from facts") == 1
|
||||||
|
|
|
@ -74,11 +74,11 @@ def test_factAddDelete():
|
||||||
id1 = cards[0].id; id2 = cards[1].id
|
id1 = cards[0].id; id2 = cards[1].id
|
||||||
assert deck.cardCount() == 2
|
assert deck.cardCount() == 2
|
||||||
assert deck.factCount() == 1
|
assert deck.factCount() == 1
|
||||||
deck.deleteCard(id1)
|
deck.delCard(id1)
|
||||||
assert deck.cardCount() == 1
|
assert deck.cardCount() == 1
|
||||||
assert deck.factCount() == 1
|
assert deck.factCount() == 1
|
||||||
# and the second should clear the fact
|
# and the second should clear the fact
|
||||||
deck.deleteCard(id2)
|
deck.delCard(id2)
|
||||||
assert deck.cardCount() == 0
|
assert deck.cardCount() == 0
|
||||||
assert deck.factCount() == 0
|
assert deck.factCount() == 0
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,6 @@ def test_findCards():
|
||||||
assert (len(deck.findCards("tag:foo")) ==
|
assert (len(deck.findCards("tag:foo")) ==
|
||||||
len(deck.findCards("tag:bar")) ==
|
len(deck.findCards("tag:bar")) ==
|
||||||
3)
|
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:foo")) == 0
|
||||||
assert len(deck.findCards("tag:bar")) == 3
|
assert len(deck.findCards("tag:bar")) == 3
|
||||||
|
|
|
@ -11,7 +11,7 @@ def test_modelDelete():
|
||||||
f['Back'] = u'2'
|
f['Back'] = u'2'
|
||||||
deck.addFact(f)
|
deck.addFact(f)
|
||||||
assert deck.cardCount() == 1
|
assert deck.cardCount() == 1
|
||||||
deck.deleteModel(deck.conf['currentModelId'])
|
deck.delModel(deck.conf['currentModelId'])
|
||||||
assert deck.cardCount() == 0
|
assert deck.cardCount() == 0
|
||||||
|
|
||||||
def test_modelCopy():
|
def test_modelCopy():
|
||||||
|
|
Loading…
Reference in a new issue