mirror of
https://github.com/ankitects/anki.git
synced 2025-11-11 07:07:13 -05:00
ensure model/template gid exists; mark schema modified when group deleted
This commit is contained in:
parent
86a7106eab
commit
c5e7756304
3 changed files with 10 additions and 2 deletions
|
|
@ -160,6 +160,7 @@ qconf=?, conf=?, data=?""",
|
|||
if not self.schemaChanged():
|
||||
# next sync will be full
|
||||
self.emptyTrash()
|
||||
runHook("modSchema")
|
||||
self.scm = intTime()
|
||||
|
||||
def schemaChanged(self):
|
||||
|
|
@ -323,7 +324,7 @@ select id from facts where id not in (select distinct fid from cards)""")
|
|||
card.id = self.nextID("cid")
|
||||
card.fid = fact.id
|
||||
card.ord = template['ord']
|
||||
card.gid = template['gid'] or fact.gid
|
||||
card.gid = self.defaultGroup(template['gid'] or fact.gid)
|
||||
card.due = due
|
||||
if flush:
|
||||
card.flush()
|
||||
|
|
@ -570,7 +571,13 @@ update facts set tags = :t, mod = :n where id = :id""", [fix(row) for row in res
|
|||
simplejson.dumps(anki.groups.defaultData)).lastrowid
|
||||
return id
|
||||
|
||||
def defaultGroup(self, id):
|
||||
if id == 1:
|
||||
return 1
|
||||
return self.db.scalar("select id from groups where id = ?", id) or 1
|
||||
|
||||
def delGroup(self, gid):
|
||||
self.modSchema()
|
||||
self.db.execute("update cards set gid = 1 where gid = ?", gid)
|
||||
self.db.execute("update facts set gid = 1 where gid = ?", gid)
|
||||
self.db.execute("delete from groups where id = ?", gid)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class Fact(object):
|
|||
else:
|
||||
self.id = None
|
||||
self._model = model
|
||||
self.gid = 1
|
||||
self.gid = deck.defaultGroup(model.conf['gid'])
|
||||
self.mid = model.id
|
||||
self.crt = intTime()
|
||||
self.mod = self.crt
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from anki.lang import _
|
|||
|
||||
# Models
|
||||
##########################################################################
|
||||
# gid may point to non-existent group
|
||||
|
||||
defaultConf = {
|
||||
'sortf': 0,
|
||||
|
|
|
|||
Loading…
Reference in a new issue