diff --git a/anki/__init__.py b/anki/__init__.py index 17303394e..ad3258d4b 100644 --- a/anki/__init__.py +++ b/anki/__init__.py @@ -45,10 +45,6 @@ elif sys.version_info[1] < 5: if sys.getfilesystemencoding().lower() in ("ascii", "ansi_x3.4-1968"): raise Exception("Anki requires a UTF-8 locale.") -import os -if not os.path.exists(os.path.expanduser("~/.no-warranty")): - raise Exception("Don't use this without reading the forum thread") - version = "1.99" from anki.storage import Collection open = Collection diff --git a/anki/models.py b/anki/models.py index 7b1373fc9..950514932 100644 --- a/anki/models.py +++ b/anki/models.py @@ -68,7 +68,7 @@ class ModelManager(object): def save(self, m=None, gencards=False): "Mark M modified if provided, and schedule registry flush." - if m: + if m and m['id']: m['mod'] = intTime() m['usn'] = self.col.usn() self._updateRequired(m) @@ -124,7 +124,8 @@ class ModelManager(object): m['flds'] = [] m['tmpls'] = [] m['tags'] = [] - return self._add(m) + m['id'] = None + return m def rem(self, m): "Delete model, and all its cards/notes." @@ -141,11 +142,11 @@ select id from cards where nid in (select id from notes where mid = ?)""", if current: self.setCurrent(self.models.values()[0]) - def _add(self, m): + def add(self, m): self._setID(m) self.update(m) self.setCurrent(m) - return m + self.save(m) def update(self, m): "Add or update an existing model. Used for syncing and merging." @@ -186,7 +187,8 @@ select id from cards where nid in (select id from notes where mid = ?)""", "Copy, save and return." m2 = copy.deepcopy(m) m2['name'] = _("%s copy") % m2['name'] - return self._add(m2) + self.add(m2) + return m2 # Fields ################################################## @@ -271,9 +273,8 @@ select id from cards where nid in (select id from notes where mid = ?)""", f['ord'] = c def _transformFields(self, m, fn): - if not self.col.db.scalar( - "select 1 from notes where mid = ? limit 1", m['id']): - # don't bump schema for a new model + # model hasn't been added yet? + if not m['id']: return self.col.modSchema() r = [] @@ -294,7 +295,8 @@ select id from cards where nid in (select id from notes where mid = ?)""", def addTemplate(self, m, template): "Note: should col.genCards() afterwards." - self.col.modSchema() + if m['id']: + self.col.modSchema() m['tmpls'].append(template) self._updateTemplOrds(m) self.save(m) diff --git a/anki/stdmodels.py b/anki/stdmodels.py index 850bc1c23..ce243294d 100644 --- a/anki/stdmodels.py +++ b/anki/stdmodels.py @@ -20,7 +20,7 @@ def addBasicModel(col): t['qfmt'] = "{{" + _("Front") + "}}" t['afmt'] = "{{" + _("Back") + "}}" mm.addTemplate(m, t) - mm.save(m) + mm.add(m) return m models.append((_("Basic"), addBasicModel)) @@ -43,7 +43,7 @@ def addClozeModel(col): t['afmt'] = ("{{cloze:%d:" + _("Text") + "}}") % n t['afmt'] += "
{{" + _("Notes") + "}}" mm.addTemplate(m, t) - mm.save(m) + mm.add(m) return m models.append((_("Cloze"), addClozeModel))