mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -04:00
rename a few methods for consistency
This commit is contained in:
parent
be5c5a2018
commit
a9b4285959
8 changed files with 24 additions and 24 deletions
|
@ -20,9 +20,9 @@ REV_CARDS_OLD_FIRST = 0
|
||||||
REV_CARDS_NEW_FIRST = 1
|
REV_CARDS_NEW_FIRST = 1
|
||||||
REV_CARDS_RANDOM = 2
|
REV_CARDS_RANDOM = 2
|
||||||
|
|
||||||
# deletion types
|
# removal types
|
||||||
DEL_CARD = 0
|
REM_CARD = 0
|
||||||
DEL_FACT = 1
|
REM_FACT = 1
|
||||||
|
|
||||||
# Labels
|
# Labels
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
20
anki/deck.py
20
anki/deck.py
|
@ -213,8 +213,8 @@ qconf=?, conf=?""",
|
||||||
# Deletion logging
|
# Deletion logging
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def _logDels(self, ids, type):
|
def _logRem(self, ids, type):
|
||||||
tbl = "cards" if type == DEL_CARD else "facts"
|
tbl = "cards" if type == REM_CARD else "facts"
|
||||||
self.db.executemany("insert into graves values (%d, ?, %d)" % (
|
self.db.executemany("insert into graves values (%d, ?, %d)" % (
|
||||||
intTime(), type), ([x] for x in ids))
|
intTime(), type), ([x] for x in ids))
|
||||||
|
|
||||||
|
@ -250,18 +250,18 @@ qconf=?, conf=?""",
|
||||||
def _randPos(self):
|
def _randPos(self):
|
||||||
return random.randrange(1, self.nextID("pos", inc=False))
|
return random.randrange(1, self.nextID("pos", inc=False))
|
||||||
|
|
||||||
def delFacts(self, ids):
|
def remFacts(self, ids):
|
||||||
self.delCards(self.db.list("select id from cards where fid in "+
|
self.remCards(self.db.list("select id from cards where fid in "+
|
||||||
ids2str(ids)))
|
ids2str(ids)))
|
||||||
|
|
||||||
def _delFacts(self, ids):
|
def _remFacts(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
|
||||||
strids = ids2str(ids)
|
strids = ids2str(ids)
|
||||||
# we need to log these independently of cards, as one side may have
|
# we need to log these independently of cards, as one side may have
|
||||||
# more card templates
|
# more card templates
|
||||||
self._logDels(ids, DEL_FACT)
|
self._logRem(ids, REM_FACT)
|
||||||
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)
|
||||||
|
|
||||||
|
@ -348,21 +348,21 @@ qconf=?, conf=?""",
|
||||||
def cardCount(self):
|
def cardCount(self):
|
||||||
return self.db.scalar("select count() from cards")
|
return self.db.scalar("select count() from cards")
|
||||||
|
|
||||||
def delCards(self, ids):
|
def remCards(self, ids):
|
||||||
"Bulk delete cards by ID."
|
"Bulk delete cards by ID."
|
||||||
if not ids:
|
if not ids:
|
||||||
return
|
return
|
||||||
sids = ids2str(ids)
|
sids = ids2str(ids)
|
||||||
fids = self.db.list("select fid from cards where id in "+sids)
|
fids = self.db.list("select fid from cards where id in "+sids)
|
||||||
# remove cards
|
# remove cards
|
||||||
self._logDels(ids, DEL_CARD)
|
self._logRem(ids, REM_CARD)
|
||||||
self.db.execute("delete from cards where id in "+sids)
|
self.db.execute("delete from cards where id in "+sids)
|
||||||
self.db.execute("delete from revlog where cid in "+sids)
|
self.db.execute("delete from revlog where cid in "+sids)
|
||||||
# then facts
|
# then facts
|
||||||
fids = self.db.list("""
|
fids = self.db.list("""
|
||||||
select id from facts where id in %s and id not in (select fid from cards)""" %
|
select id from facts where id in %s and id not in (select fid from cards)""" %
|
||||||
ids2str(fids))
|
ids2str(fids))
|
||||||
self._delFacts(fids)
|
self._remFacts(fids)
|
||||||
|
|
||||||
# Field checksums and sorting fields
|
# Field checksums and sorting fields
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
@ -600,7 +600,7 @@ where c.fid == f.id
|
||||||
# delete any facts with missing cards
|
# delete any facts with missing cards
|
||||||
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._delFacts(ids)
|
self._remFacts(ids)
|
||||||
# tags
|
# tags
|
||||||
self.tags.registerFacts()
|
self.tags.registerFacts()
|
||||||
# field cache
|
# field cache
|
||||||
|
|
|
@ -82,7 +82,7 @@ class GroupManager(object):
|
||||||
self.save(g)
|
self.save(g)
|
||||||
return int(id)
|
return int(id)
|
||||||
|
|
||||||
def del_(self, gid):
|
def rem(self, gid):
|
||||||
self.deck.modSchema()
|
self.deck.modSchema()
|
||||||
self.deck.db.execute("update cards set gid = 1 where gid = ?", gid)
|
self.deck.db.execute("update cards set gid = 1 where gid = ?", gid)
|
||||||
self.deck.db.execute("update facts set gid = 1 where gid = ?", gid)
|
self.deck.db.execute("update facts set gid = 1 where gid = ?", gid)
|
||||||
|
|
|
@ -114,11 +114,11 @@ class ModelManager(object):
|
||||||
m['tags'] = []
|
m['tags'] = []
|
||||||
return self._add(m)
|
return self._add(m)
|
||||||
|
|
||||||
def del_(self, m):
|
def rem(self, m):
|
||||||
"Delete model, and all its cards/facts."
|
"Delete model, and all its cards/facts."
|
||||||
self.deck.modSchema()
|
self.deck.modSchema()
|
||||||
# delete facts/cards
|
# delete facts/cards
|
||||||
self.deck.delCards(self.deck.db.list("""
|
self.deck.remCards(self.deck.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 = ?)""",
|
||||||
m['id']))
|
m['id']))
|
||||||
# then the model
|
# then the model
|
||||||
|
@ -312,7 +312,7 @@ select id from cards where fid in (select id from facts where mid = ?)""",
|
||||||
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 = ?""",
|
||||||
m['id'], ord)
|
m['id'], ord)
|
||||||
self.deck.delCards(cids)
|
self.deck.remCards(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
|
||||||
|
@ -385,4 +385,4 @@ select id from facts where mid = ?)""" % " ".join(map), m['id'])
|
||||||
deleted.append(cid)
|
deleted.append(cid)
|
||||||
self.deck.db.executemany(
|
self.deck.db.executemany(
|
||||||
"update cards set ord=:new where id=:cid", d)
|
"update cards set ord=:new where id=:cid", d)
|
||||||
self.deck.delCards(deleted)
|
self.deck.remCards(deleted)
|
||||||
|
|
|
@ -152,8 +152,8 @@ class Syncer(object):
|
||||||
|
|
||||||
def deletions(self, lastSync):
|
def deletions(self, lastSync):
|
||||||
sql = "select oid from graves where time > ? and type = ?"
|
sql = "select oid from graves where time > ? and type = ?"
|
||||||
return [self.deck.db.list(sql, lastSync, DEL_FACT),
|
return [self.deck.db.list(sql, lastSync, REM_FACT),
|
||||||
self.deck.db.list(sql, lastSync, DEL_CARD)]
|
self.deck.db.list(sql, lastSync, REM_CARD)]
|
||||||
|
|
||||||
def delete(self, deletions):
|
def delete(self, deletions):
|
||||||
self.deck.delFacts(deletions[0])
|
self.deck.delFacts(deletions[0])
|
||||||
|
|
|
@ -58,7 +58,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.delCards([cid])
|
deck.remCards([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
|
||||||
|
|
|
@ -75,11 +75,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.delCards([id1])
|
deck.remCards([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.delCards([id2])
|
deck.remCards([id2])
|
||||||
assert deck.cardCount() == 0
|
assert deck.cardCount() == 0
|
||||||
assert deck.factCount() == 0
|
assert deck.factCount() == 0
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,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.models.del_(deck.models.get(deck.conf['currentModelId']))
|
deck.models.rem(deck.models.get(deck.conf['currentModelId']))
|
||||||
assert deck.cardCount() == 0
|
assert deck.cardCount() == 0
|
||||||
|
|
||||||
def test_modelCopy():
|
def test_modelCopy():
|
||||||
|
|
Loading…
Reference in a new issue