mirror of
https://github.com/ankitects/anki.git
synced 2025-11-14 08:37:11 -05:00
add some group utilities
This commit is contained in:
parent
f9c3b27e5d
commit
17ee7757de
4 changed files with 66 additions and 13 deletions
31
anki/deck.py
31
anki/deck.py
|
|
@ -593,6 +593,37 @@ update facts set tags = :t, mod = :n where id = :id""", [fix(row) for row in res
|
||||||
def delTags(self, ids, tags):
|
def delTags(self, ids, tags):
|
||||||
self.addTags(ids, tags, False)
|
self.addTags(ids, tags, False)
|
||||||
|
|
||||||
|
# Groups
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
def groups(self):
|
||||||
|
"A list of all group names."
|
||||||
|
return self.db.list("select name from groups")
|
||||||
|
|
||||||
|
def groupId(self, name):
|
||||||
|
"Return the id for NAME, creating if necessary."
|
||||||
|
id = self.db.scalar("select id from groups where name = ?", name)
|
||||||
|
if not id:
|
||||||
|
id = self.db.execute("insert into groups values (?,?,?,?)",
|
||||||
|
self.nextID("gid"), intTime(), name,
|
||||||
|
1).lastrowid
|
||||||
|
return id
|
||||||
|
|
||||||
|
def delGroup(self, gid):
|
||||||
|
self.db.scalar("delete from groups where id = ?", gid)
|
||||||
|
|
||||||
|
def groupConf(self, gid):
|
||||||
|
return simplejson.loads(
|
||||||
|
self.db.scalar("""
|
||||||
|
select conf from gconf where id = (select gcid from groups where id = ?)""",
|
||||||
|
gid))
|
||||||
|
|
||||||
|
def activeGroups(self, type):
|
||||||
|
return self.qconf[type+"Groups"]
|
||||||
|
|
||||||
|
def setActiveGroups(self, type, list):
|
||||||
|
self.qconf[type+"Groups"] = list
|
||||||
|
|
||||||
# Finding cards
|
# Finding cards
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,7 @@ class Scheduler(object):
|
||||||
card.flushSched()
|
card.flushSched()
|
||||||
|
|
||||||
def counts(self):
|
def counts(self):
|
||||||
# FIXME: should learn count include new cards due today, or be separate?
|
return (self.learnCount, self.revCount, self.newCount)
|
||||||
return (self.learnCount, self.revCount)
|
|
||||||
|
|
||||||
def timeToday(self):
|
def timeToday(self):
|
||||||
"Time spent learning today, in seconds."
|
"Time spent learning today, in seconds."
|
||||||
|
|
@ -507,9 +506,7 @@ insert into revlog values (
|
||||||
def confForCard(self, card):
|
def confForCard(self, card):
|
||||||
id = self.groupConfs[card.gid]
|
id = self.groupConfs[card.gid]
|
||||||
if id not in self.confCache:
|
if id not in self.confCache:
|
||||||
self.confCache[id] = simplejson.loads(
|
self.confCache[id] = self.deck.groupConf(id)
|
||||||
self.db.scalar("select conf from gconf where id = :id",
|
|
||||||
id=id))
|
|
||||||
return self.confCache[id]
|
return self.confCache[id]
|
||||||
|
|
||||||
def resetSchedBuried(self):
|
def resetSchedBuried(self):
|
||||||
|
|
@ -518,7 +515,7 @@ insert into revlog values (
|
||||||
"update cards set queue = type where queue = -3")
|
"update cards set queue = type where queue = -3")
|
||||||
|
|
||||||
def groupLimit(self, type):
|
def groupLimit(self, type):
|
||||||
l = self.deck.qconf[type+"Groups"]
|
l = self.deck.activeGroups(type)
|
||||||
if not l:
|
if not l:
|
||||||
# everything
|
# everything
|
||||||
return ""
|
return ""
|
||||||
|
|
|
||||||
|
|
@ -115,13 +115,6 @@ create table if not exists models (
|
||||||
css text not null
|
css text not null
|
||||||
);
|
);
|
||||||
|
|
||||||
create table if not exists gconf (
|
|
||||||
id integer primary key,
|
|
||||||
mod integer not null,
|
|
||||||
name text not null,
|
|
||||||
conf text not null
|
|
||||||
);
|
|
||||||
|
|
||||||
create table if not exists groups (
|
create table if not exists groups (
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
mod integer not null,
|
mod integer not null,
|
||||||
|
|
@ -129,6 +122,13 @@ create table if not exists groups (
|
||||||
gcid integer not null
|
gcid integer not null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create table if not exists gconf (
|
||||||
|
id integer primary key,
|
||||||
|
mod integer not null,
|
||||||
|
name text not null,
|
||||||
|
conf text not null
|
||||||
|
);
|
||||||
|
|
||||||
create table if not exists media (
|
create table if not exists media (
|
||||||
file text primary key,
|
file text primary key,
|
||||||
mod integer not null,
|
mod integer not null,
|
||||||
|
|
|
||||||
|
|
@ -123,3 +123,28 @@ def test_upgrade():
|
||||||
deck = Deck(dst)
|
deck = Deck(dst)
|
||||||
# now's a good time to test the integrity check too
|
# now's a good time to test the integrity check too
|
||||||
deck.fixIntegrity()
|
deck.fixIntegrity()
|
||||||
|
|
||||||
|
def test_groups():
|
||||||
|
deck = getEmptyDeck()
|
||||||
|
# we start with a standard group
|
||||||
|
assert len(deck.groups()) == 1
|
||||||
|
# it should have an id of 1
|
||||||
|
assert deck.groupId(deck.groups()[0]) == 1
|
||||||
|
# create a new group
|
||||||
|
assert deck.groupId("new group") == 2
|
||||||
|
assert len(deck.groups()) == 2
|
||||||
|
# should get the same id
|
||||||
|
assert deck.groupId("new group") == 2
|
||||||
|
# deleting a group should not recycle ids
|
||||||
|
deck.delGroup(2)
|
||||||
|
assert len(deck.groups()) == 1
|
||||||
|
assert deck.groupId("another group") == 3
|
||||||
|
# the newly created group should have a default schedule
|
||||||
|
conf = deck.groupConf(3)
|
||||||
|
assert conf == deck.groupConf(1)
|
||||||
|
# by default, everything should be shown
|
||||||
|
assert not deck.activeGroups('rev')
|
||||||
|
assert not deck.activeGroups('new')
|
||||||
|
# set new cards to only 'another group'
|
||||||
|
deck.setActiveGroups('new', [3])
|
||||||
|
assert deck.activeGroups('new') == [3]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue