mirror of
https://github.com/ankitects/anki.git
synced 2025-11-07 13:17:12 -05:00
ensure the list of note types is not empty
fixes an issue opening the add screen if a user manages to delete all their note types with an add-on or a sync
This commit is contained in:
parent
4a2f39e8f4
commit
8497da27cf
2 changed files with 10 additions and 0 deletions
|
|
@ -872,6 +872,9 @@ and type = 0""", intTime(), self.usn())
|
||||||
curs.execute("update revlog set ivl=round(ivl),lastIvl=round(lastIvl) where ivl!=round(ivl) or lastIvl!=round(lastIvl)")
|
curs.execute("update revlog set ivl=round(ivl),lastIvl=round(lastIvl) where ivl!=round(ivl) or lastIvl!=round(lastIvl)")
|
||||||
if curs.rowcount:
|
if curs.rowcount:
|
||||||
problems.append("Fixed %d review history entries with v2 scheduler bug." % curs.rowcount)
|
problems.append("Fixed %d review history entries with v2 scheduler bug." % curs.rowcount)
|
||||||
|
# models
|
||||||
|
if self.models.ensureNotEmpty():
|
||||||
|
problems.append("Added missing note type.")
|
||||||
# and finally, optimize
|
# and finally, optimize
|
||||||
self.optimize()
|
self.optimize()
|
||||||
newSize = os.stat(self.path)[stat.ST_SIZE]
|
newSize = os.stat(self.path)[stat.ST_SIZE]
|
||||||
|
|
|
||||||
|
|
@ -96,10 +96,17 @@ class ModelManager:
|
||||||
def flush(self):
|
def flush(self):
|
||||||
"Flush the registry if any models were changed."
|
"Flush the registry if any models were changed."
|
||||||
if self.changed:
|
if self.changed:
|
||||||
|
self.ensureNotEmpty()
|
||||||
self.col.db.execute("update col set models = ?",
|
self.col.db.execute("update col set models = ?",
|
||||||
json.dumps(self.models))
|
json.dumps(self.models))
|
||||||
self.changed = False
|
self.changed = False
|
||||||
|
|
||||||
|
def ensureNotEmpty(self):
|
||||||
|
if not self.models:
|
||||||
|
from anki.stdmodels import addBasicModel
|
||||||
|
addBasicModel(self.col)
|
||||||
|
return True
|
||||||
|
|
||||||
# Retrieving and creating models
|
# Retrieving and creating models
|
||||||
#############################################################
|
#############################################################
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue