From 911069d371745d4d14f76548ae3c2add0cd92b39 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 11 Mar 2011 04:52:50 +0900 Subject: [PATCH] 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. --- anki/cards.py | 12 +++--------- anki/deck.py | 12 ++---------- anki/facts.py | 2 +- anki/models.py | 1 + anki/storage.py | 11 +++++------ 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/anki/cards.py b/anki/cards.py index 1b7e50447..e215ed8ec 100644 --- a/anki/cards.py +++ b/anki/cards.py @@ -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, diff --git a/anki/deck.py b/anki/deck.py index ce7e6502f..e997ef81d 100644 --- a/anki/deck.py +++ b/anki/deck.py @@ -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 = [] diff --git a/anki/facts.py b/anki/facts.py index d906643a7..b8d416592 100644 --- a/anki/facts.py +++ b/anki/facts.py @@ -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 ################################################## diff --git a/anki/models.py b/anki/models.py index 451cf8321..3e53a3bfd 100644 --- a/anki/models.py +++ b/anki/models.py @@ -173,6 +173,7 @@ defaultTemplateConf = { 'bg': "#000", 'allowEmptyAns': None, 'typeAnswer': None, + 'gid': None } class Template(object): diff --git a/anki/storage.py b/anki/storage.py index 46d068d43..0fb195b9b 100644 --- a/anki/storage.py +++ b/anki/storage.py @@ -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)