mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
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:
parent
4f2ecda980
commit
911069d371
5 changed files with 12 additions and 26 deletions
|
@ -13,12 +13,8 @@ MAX_TIMER = 60
|
||||||
# Type: 0=learning, 1=due, 2=new
|
# Type: 0=learning, 1=due, 2=new
|
||||||
# Queue: 0=learning, 1=due, 2=new
|
# Queue: 0=learning, 1=due, 2=new
|
||||||
# -1=suspended, -2=user buried, -3=sched buried
|
# -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.
|
# Due is used differently for different queues.
|
||||||
# - new queue: fact.id
|
# - new queue: fact id
|
||||||
# - rev queue: integer day
|
# - rev queue: integer day
|
||||||
# - lrn queue: integer timestamp
|
# - lrn queue: integer timestamp
|
||||||
|
|
||||||
|
@ -32,7 +28,7 @@ class Card(object):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.load()
|
self.load()
|
||||||
else:
|
else:
|
||||||
# to flush, set fid, tid, due and ord
|
# to flush, set fid, tid, and due
|
||||||
self.id = None
|
self.id = None
|
||||||
self.gid = 1
|
self.gid = 1
|
||||||
self.crt = intTime()
|
self.crt = intTime()
|
||||||
|
@ -52,7 +48,6 @@ class Card(object):
|
||||||
self.fid,
|
self.fid,
|
||||||
self.tid,
|
self.tid,
|
||||||
self.gid,
|
self.gid,
|
||||||
self.ord,
|
|
||||||
self.crt,
|
self.crt,
|
||||||
self.mod,
|
self.mod,
|
||||||
self.type,
|
self.type,
|
||||||
|
@ -73,12 +68,11 @@ class Card(object):
|
||||||
self.deck.db.execute(
|
self.deck.db.execute(
|
||||||
"""
|
"""
|
||||||
insert or replace into cards values
|
insert or replace into cards values
|
||||||
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||||
self.id,
|
self.id,
|
||||||
self.fid,
|
self.fid,
|
||||||
self.tid,
|
self.tid,
|
||||||
self.gid,
|
self.gid,
|
||||||
self.ord,
|
|
||||||
self.crt,
|
self.crt,
|
||||||
self.mod,
|
self.mod,
|
||||||
self.type,
|
self.type,
|
||||||
|
|
12
anki/deck.py
12
anki/deck.py
|
@ -169,7 +169,6 @@ qconf=?, conf=?, data=?""",
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.sched.reset()
|
self.sched.reset()
|
||||||
|
|
||||||
|
|
||||||
# Times
|
# Times
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -384,7 +383,7 @@ due > :now and due < :now""", now=time.time())
|
||||||
"Return a new fact with the current model."
|
"Return a new fact with the current model."
|
||||||
return anki.facts.Fact(self, self.currentModel())
|
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."
|
"Add a fact to the deck. Return number of new cards."
|
||||||
# check we have card models available
|
# check we have card models available
|
||||||
cms = self.findTemplates(fact)
|
cms = self.findTemplates(fact)
|
||||||
|
@ -400,13 +399,11 @@ due > :now and due < :now""", now=time.time())
|
||||||
# flush the fact so we get its id
|
# flush the fact so we get its id
|
||||||
fact.flush()
|
fact.flush()
|
||||||
for template in cms:
|
for template in cms:
|
||||||
print "fixme:specify group on fact add"
|
|
||||||
group = self.groupForTemplate(template)
|
|
||||||
card = anki.cards.Card(self)
|
card = anki.cards.Card(self)
|
||||||
card.fid = fact.id
|
card.fid = fact.id
|
||||||
card.tid = template.id
|
card.tid = template.id
|
||||||
card.ord = template.ord
|
card.ord = template.ord
|
||||||
card.gid = 1 #group.id
|
card.gid = template.conf['gid'] or gid
|
||||||
if isRandom:
|
if isRandom:
|
||||||
card.due = due
|
card.due = due
|
||||||
else:
|
else:
|
||||||
|
@ -418,11 +415,6 @@ due > :now and due < :now""", now=time.time())
|
||||||
self.registerTags(fact.tags)
|
self.registerTags(fact.tags)
|
||||||
return ncards
|
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):
|
def findTemplates(self, fact, checkActive=True):
|
||||||
"Return active, non-empty templates."
|
"Return active, non-empty templates."
|
||||||
ok = []
|
ok = []
|
||||||
|
|
|
@ -67,7 +67,7 @@ insert or replace into facts values (?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||||
|
|
||||||
def cards(self):
|
def cards(self):
|
||||||
return [self.deck.getCard(id) for id in self.deck.db.list(
|
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
|
# Dict interface
|
||||||
##################################################
|
##################################################
|
||||||
|
|
|
@ -173,6 +173,7 @@ defaultTemplateConf = {
|
||||||
'bg': "#000",
|
'bg': "#000",
|
||||||
'allowEmptyAns': None,
|
'allowEmptyAns': None,
|
||||||
'typeAnswer': None,
|
'typeAnswer': None,
|
||||||
|
'gid': None
|
||||||
}
|
}
|
||||||
|
|
||||||
class Template(object):
|
class Template(object):
|
||||||
|
|
|
@ -70,7 +70,6 @@ create table if not exists cards (
|
||||||
fid integer not null,
|
fid integer not null,
|
||||||
tid integer not null,
|
tid integer not null,
|
||||||
gid integer not null,
|
gid integer not null,
|
||||||
ord integer not null,
|
|
||||||
crt integer not null,
|
crt integer not null,
|
||||||
mod integer not null,
|
mod integer not null,
|
||||||
type integer not null,
|
type integer not null,
|
||||||
|
@ -254,10 +253,10 @@ def _upgradeSchema(db):
|
||||||
_insertWithIdChange(db, map, 0, "reviewHistory", 12)
|
_insertWithIdChange(db, map, 0, "reviewHistory", 12)
|
||||||
# move back, preserving new ids
|
# move back, preserving new ids
|
||||||
db.execute("""
|
db.execute("""
|
||||||
insert into cards select rowid, factId, cardModelId, 1, ordinal,
|
insert into cards select rowid, factId, cardModelId, 1, cast(created as int),
|
||||||
cast(created as int), cast(modified as int), relativeDelay, type, due,
|
cast(modified as int), relativeDelay, type, due, cast(interval as int),
|
||||||
cast(interval as int), cast(factor*1000 as int), reps, successive, noCount,
|
cast(factor*1000 as int), reps, successive, noCount, 0, 0, "" from cards2
|
||||||
0, 0, "" from cards2 order by created""")
|
order by created""")
|
||||||
db.execute("drop table cards2")
|
db.execute("drop table cards2")
|
||||||
|
|
||||||
# tags
|
# tags
|
||||||
|
@ -302,7 +301,7 @@ from facts order by created""")
|
||||||
row.append(minimizeHTML("\x1f".join([x[1] for x in sorted(fields[oldid])])))
|
row.append(minimizeHTML("\x1f".join([x[1] for x in sorted(fields[oldid])])))
|
||||||
data.append(row)
|
data.append(row)
|
||||||
# use the new order to rewrite fact ids in cards table
|
# 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
|
# and put the facts into the new table
|
||||||
db.execute("drop table facts")
|
db.execute("drop table facts")
|
||||||
_addSchema(db, False)
|
_addSchema(db, False)
|
||||||
|
|
Loading…
Reference in a new issue