mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -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_RANDOM = 2
|
||||
|
||||
# deletion types
|
||||
DEL_CARD = 0
|
||||
DEL_FACT = 1
|
||||
# removal types
|
||||
REM_CARD = 0
|
||||
REM_FACT = 1
|
||||
|
||||
# Labels
|
||||
##########################################################################
|
||||
|
|
20
anki/deck.py
20
anki/deck.py
|
@ -213,8 +213,8 @@ qconf=?, conf=?""",
|
|||
# Deletion logging
|
||||
##########################################################################
|
||||
|
||||
def _logDels(self, ids, type):
|
||||
tbl = "cards" if type == DEL_CARD else "facts"
|
||||
def _logRem(self, ids, type):
|
||||
tbl = "cards" if type == REM_CARD else "facts"
|
||||
self.db.executemany("insert into graves values (%d, ?, %d)" % (
|
||||
intTime(), type), ([x] for x in ids))
|
||||
|
||||
|
@ -250,18 +250,18 @@ qconf=?, conf=?""",
|
|||
def _randPos(self):
|
||||
return random.randrange(1, self.nextID("pos", inc=False))
|
||||
|
||||
def delFacts(self, ids):
|
||||
self.delCards(self.db.list("select id from cards where fid in "+
|
||||
def remFacts(self, ids):
|
||||
self.remCards(self.db.list("select id from cards where fid in "+
|
||||
ids2str(ids)))
|
||||
|
||||
def _delFacts(self, ids):
|
||||
def _remFacts(self, ids):
|
||||
"Bulk delete facts by ID. Don't call this directly."
|
||||
if not ids:
|
||||
return
|
||||
strids = ids2str(ids)
|
||||
# we need to log these independently of cards, as one side may have
|
||||
# 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 fsums where fid in %s" % strids)
|
||||
|
||||
|
@ -348,21 +348,21 @@ qconf=?, conf=?""",
|
|||
def cardCount(self):
|
||||
return self.db.scalar("select count() from cards")
|
||||
|
||||
def delCards(self, ids):
|
||||
def remCards(self, ids):
|
||||
"Bulk delete cards by ID."
|
||||
if not ids:
|
||||
return
|
||||
sids = ids2str(ids)
|
||||
fids = self.db.list("select fid from cards where id in "+sids)
|
||||
# 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 revlog where cid in "+sids)
|
||||
# then facts
|
||||
fids = self.db.list("""
|
||||
select id from facts where id in %s and id not in (select fid from cards)""" %
|
||||
ids2str(fids))
|
||||
self._delFacts(fids)
|
||||
self._remFacts(fids)
|
||||
|
||||
# Field checksums and sorting fields
|
||||
##########################################################################
|
||||
|
@ -600,7 +600,7 @@ where c.fid == f.id
|
|||
# delete any facts with missing cards
|
||||
ids = self.db.list("""
|
||||
select id from facts where id not in (select distinct fid from cards)""")
|
||||
self._delFacts(ids)
|
||||
self._remFacts(ids)
|
||||
# tags
|
||||
self.tags.registerFacts()
|
||||
# field cache
|
||||
|
|
|
@ -82,7 +82,7 @@ class GroupManager(object):
|
|||
self.save(g)
|
||||
return int(id)
|
||||
|
||||
def del_(self, gid):
|
||||
def rem(self, gid):
|
||||
self.deck.modSchema()
|
||||
self.deck.db.execute("update cards 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'] = []
|
||||
return self._add(m)
|
||||
|
||||
def del_(self, m):
|
||||
def rem(self, m):
|
||||
"Delete model, and all its cards/facts."
|
||||
self.deck.modSchema()
|
||||
# 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 = ?)""",
|
||||
m['id']))
|
||||
# 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("""
|
||||
select c.id from cards c, facts f where c.fid=f.id and mid = ? and ord = ?""",
|
||||
m['id'], ord)
|
||||
self.deck.delCards(cids)
|
||||
self.deck.remCards(cids)
|
||||
# shift ordinals
|
||||
self.deck.db.execute("""
|
||||
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)
|
||||
self.deck.db.executemany(
|
||||
"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):
|
||||
sql = "select oid from graves where time > ? and type = ?"
|
||||
return [self.deck.db.list(sql, lastSync, DEL_FACT),
|
||||
self.deck.db.list(sql, lastSync, DEL_CARD)]
|
||||
return [self.deck.db.list(sql, lastSync, REM_FACT),
|
||||
self.deck.db.list(sql, lastSync, REM_CARD)]
|
||||
|
||||
def delete(self, deletions):
|
||||
self.deck.delFacts(deletions[0])
|
||||
|
|
|
@ -58,7 +58,7 @@ def test_delete():
|
|||
deck.reset()
|
||||
deck.sched.answerCard(deck.sched.getCard(), 2)
|
||||
assert deck.db.scalar("select count() from revlog") == 1
|
||||
deck.delCards([cid])
|
||||
deck.remCards([cid])
|
||||
assert deck.cardCount() == 0
|
||||
assert deck.factCount() == 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
|
||||
assert deck.cardCount() == 2
|
||||
assert deck.factCount() == 1
|
||||
deck.delCards([id1])
|
||||
deck.remCards([id1])
|
||||
assert deck.cardCount() == 1
|
||||
assert deck.factCount() == 1
|
||||
# and the second should clear the fact
|
||||
deck.delCards([id2])
|
||||
deck.remCards([id2])
|
||||
assert deck.cardCount() == 0
|
||||
assert deck.factCount() == 0
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ def test_modelDelete():
|
|||
f['Back'] = u'2'
|
||||
deck.addFact(f)
|
||||
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
|
||||
|
||||
def test_modelCopy():
|
||||
|
|
Loading…
Reference in a new issue