remove ord from cards, give templates an optional gid, change addFact()

When adding facts, you can now pass in a group id which the GUI should support
editing. Templates will have an optional group id which overrides the provided
id, so users can automatically put certain card types in a different group (or
all of them, if desired). Greying out the group box in the GUI in that case
would be a good idea.
This commit is contained in:
Damien Elmes 2011-03-11 04:52:50 +09:00
parent 4f2ecda980
commit 911069d371
5 changed files with 12 additions and 26 deletions

View file

@ -13,12 +13,8 @@ MAX_TIMER = 60
# Type: 0=learning, 1=due, 2=new
# Queue: 0=learning, 1=due, 2=new
# -1=suspended, -2=user buried, -3=sched buried
# Group: scheduling group
# Ordinal: card template # for fact
# Flags: unused; reserved for future use
# Due is used differently for different queues.
# - new queue: fact.id
# - new queue: fact id
# - rev queue: integer day
# - lrn queue: integer timestamp
@ -32,7 +28,7 @@ class Card(object):
self.id = id
self.load()
else:
# to flush, set fid, tid, due and ord
# to flush, set fid, tid, and due
self.id = None
self.gid = 1
self.crt = intTime()
@ -52,7 +48,6 @@ class Card(object):
self.fid,
self.tid,
self.gid,
self.ord,
self.crt,
self.mod,
self.type,
@ -73,12 +68,11 @@ class Card(object):
self.deck.db.execute(
"""
insert or replace into cards values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
self.id,
self.fid,
self.tid,
self.gid,
self.ord,
self.crt,
self.mod,
self.type,

View file

@ -169,7 +169,6 @@ qconf=?, conf=?, data=?""",
def reset(self):
self.sched.reset()
# Times
##########################################################################
@ -384,7 +383,7 @@ due > :now and due < :now""", now=time.time())
"Return a new fact with the current model."
return anki.facts.Fact(self, self.currentModel())
def addFact(self, fact):
def addFact(self, fact, gid=1):
"Add a fact to the deck. Return number of new cards."
# check we have card models available
cms = self.findTemplates(fact)
@ -400,13 +399,11 @@ due > :now and due < :now""", now=time.time())
# flush the fact so we get its id
fact.flush()
for template in cms:
print "fixme:specify group on fact add"
group = self.groupForTemplate(template)
card = anki.cards.Card(self)
card.fid = fact.id
card.tid = template.id
card.ord = template.ord
card.gid = 1 #group.id
card.gid = template.conf['gid'] or gid
if isRandom:
card.due = due
else:
@ -418,11 +415,6 @@ due > :now and due < :now""", now=time.time())
self.registerTags(fact.tags)
return ncards
def groupForTemplate(self, template):
return 1
id = self.conf['currentGroupId']
return self.db.query(anki.groups.GroupConf).get(id).load()
def findTemplates(self, fact, checkActive=True):
"Return active, non-empty templates."
ok = []

View file

@ -67,7 +67,7 @@ insert or replace into facts values (?, ?, ?, ?, ?, ?, ?, ?)""",
def cards(self):
return [self.deck.getCard(id) for id in self.deck.db.list(
"select id from cards where fid = ? order by ord", self.id)]
"select id from cards where fid = ? order by id", self.id)]
# Dict interface
##################################################

View file

@ -173,6 +173,7 @@ defaultTemplateConf = {
'bg': "#000",
'allowEmptyAns': None,
'typeAnswer': None,
'gid': None
}
class Template(object):

View file

@ -70,7 +70,6 @@ create table if not exists cards (
fid integer not null,
tid integer not null,
gid integer not null,
ord integer not null,
crt integer not null,
mod integer not null,
type integer not null,
@ -254,10 +253,10 @@ def _upgradeSchema(db):
_insertWithIdChange(db, map, 0, "reviewHistory", 12)
# move back, preserving new ids
db.execute("""
insert into cards select rowid, factId, cardModelId, 1, ordinal,
cast(created as int), cast(modified as int), relativeDelay, type, due,
cast(interval as int), cast(factor*1000 as int), reps, successive, noCount,
0, 0, "" from cards2 order by created""")
insert into cards select rowid, factId, cardModelId, 1, cast(created as int),
cast(modified as int), relativeDelay, type, due, cast(interval as int),
cast(factor*1000 as int), reps, successive, noCount, 0, 0, "" from cards2
order by created""")
db.execute("drop table cards2")
# tags
@ -302,7 +301,7 @@ from facts order by created""")
row.append(minimizeHTML("\x1f".join([x[1] for x in sorted(fields[oldid])])))
data.append(row)
# use the new order to rewrite fact ids in cards table
_insertWithIdChange(db, map, 1, "cards", 18)
_insertWithIdChange(db, map, 1, "cards", 17)
# and put the facts into the new table
db.execute("drop table facts")
_addSchema(db, False)